0% found this document useful (0 votes)
2 views18 pages

Merlytics Python

The document contains a series of Python programming questions and answers, covering topics such as identifiers, data types, functions, loops, and error handling. Each question is followed by multiple-choice options and the correct answer with a brief explanation. The document is structured in a quiz format, providing a comprehensive overview of Python concepts.

Uploaded by

saiwinnu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views18 pages

Merlytics Python

The document contains a series of Python programming questions and answers, covering topics such as identifiers, data types, functions, loops, and error handling. Each question is followed by multiple-choice options and the correct answer with a brief explanation. The document is structured in a quiz format, providing a comprehensive overview of Python concepts.

Uploaded by

saiwinnu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

1. What is the maximum length of a Python identifier?

A. 16 characters
B. 32 characters
C. 64 characters
D. No fixed length

✅Answer: D
➡✅Python identifiers can be of arbitrary length.

2. What will be the output?


python
CopyEdit
print(2**3 + (5 + 6)**(1 + 1))

A. 49
B. 121
C. 129
D. 144

✅Answer: C
➡✅2³ + 11² = 8 + 121 = 129

3. What is the datatype of var?


python
CopyEdit
var = 10
print(type(var))
var = "Hello"
print(type(var))

A. int, str
B. str, int
C. int, int
D. str, str

✅Answer: A
➡✅Python variables are dynamically typed.
4. How is a code block indicated in Python?

A. Brackets
B. Begin-End
C. Indentation
D. Curly braces

✅Answer: C
➡✅Indentation defines blocks of code in Python.

5. What is the output?


python
CopyEdit
a = [1, 2, 3]
a = tuple(a)
a[0] = 2

A. (2, 2, 3)
B. Error
C. (1, 2, 3)
D. None

✅Answer: B
➡✅Tuples are immutable — assignment to index not allowed.

6. Output of this code?


python
CopyEdit
print(type(5 / 2))
print(type(5 // 2))

A. float, int
B. int, float
C. float, float
D. int, int

✅Answer: A
➡✅/ is float division, // is integer division.
7. Output of the following?
python
CopyEdit
a = [1, 2, 3, 4, 5]
sum = 0
for ele in a:
sum += ele
print(sum)

A. 10
B. 15
C. 5
D. 0

✅Answer: B
➡✅Sum of elements is 15.

8. Output of this snippet?


python
CopyEdit
a=3
b=1
print(a, b)
a, b = b, a
print(a, b)

A. 3 1 and 1 3
B. 1 3 and 3 1
C. 3 1 and 3 1
D. 1 1 and 3 3

✅Answer: A
➡✅Swapping variables using tuple unpacking.

9. Output?
python
CopyEdit
a = [1, 2]
print(a * 3)

A. [1, 2, 1, 2, 1, 2]
B. [3, 6]
C. [1, 2, 3]
D. Error

✅Answer: A
➡✅List gets replicated.

10. Which loop type is NOT supported in Python?

A. for
B. while
C. do-while
D. nested

✅Answer: C
➡✅Python does not have native do-while loops.

11. Output?
python
CopyEdit
example = ["Sunday", "Monday", "Tuesday", "Wednesday"]
del example[2]
print(example)

A. ['Sunday', 'Tuesday', 'Wednesday']


B. ['Sunday', 'Monday', 'Wednesday']
C. Error
D. None

✅Answer: B
➡✅Index 2 ('Tuesday') is deleted.

12. How to check if item exists in list a?

A. x in a
B. a.__contains__(x)
C. Both A and B
D. None
✅Answer: C
➡✅Both are valid methods.

13. What is type of sorted_numbers?


python
CopyEdit
numbers = (4, 7, 19)
sorted_numbers = sorted(numbers)

A. tuple
B. list
C. set
D. dict

✅Answer: B
➡✅sorted() returns a list.

14. Output of thrive function?


python
CopyEdit
def thrive(n):
if n % 15 == 0:
print("thrive", end=" ")
elif n % 3 != 0 and n % 5 != 0:
print("neither", end=" ")
elif n % 3 == 0:
print("three", end=" ")
elif n % 5 == 0:
print("five", end=" ")
thrive(35); thrive(56); thrive(15); thrive(39)

A. thrive three neither five


B. five neither thrive three
C. thrive neither three five
D. Error

✅Answer: B
➡✅Based on divisibility by 3, 5, or both.

15. What is the type of even_numbers?


python
CopyEdit
even = lambda a: a % 2 == 0
even_numbers = filter(even, [2, 4, 6])

A. list
B. tuple
C. filter
D. map

✅Answer: C
➡✅filter() returns a filter object.

16. Output?
python
CopyEdit
numbers = (4, 7, 19)
sorted_numbers = sorted(numbers)
odd_numbers = [x for x in sorted_numbers if x % 2 != 0]
print(odd_numbers)

A. [4]
B. [7, 19]
C. [4, 7, 19]
D. [19]

✅Answer: B
➡✅List comprehension filters odd numbers.

17. Output of this?


python
CopyEdit
def check(a):
print("Even" if a % 2 == 0 else "Odd")
check(12)

A. Even
B. Odd
C. Error
D. 12
✅Answer: A
➡✅Ternary operator used for condition.

18. Output?
python
CopyEdit
example = ["Sunday", "Monday", "Tuesday", "Wednesday"]
print(example[-3:-1])

A. ['Monday', 'Tuesday']
B. ['Sunday', 'Monday']
C. ['Tuesday', 'Wednesday']
D. Error

✅Answer: A
➡✅Negative slicing starts from end.

19. Output?
python
CopyEdit
def is_even(number):
message = f"{number} is an even number" if number % 2 == 0 else f"{number} is an odd number"
return message
print(is_even(54))

A. 54 is even number
B. 54 is an even number
C. 54 even
D. Error

✅Answer: B
➡✅Uses f-string and ternary operator.

20. What is the output?


python
CopyEdit
dict1 = {'first': 'sunday', 'second': 'monday'}
dict2 = {1: 3, 2: 4}
dict1.update(dict2)
print(dict1)

A. {'first': 'sunday', 'second': 'monday'}


B. Error
C. {'first': 'sunday', 'second': 'monday', 1: 3, 2: 4}
D. {'first': 3, 'second': 4}

✅Answer: C
➡✅update() merges dictionaries.

I'll continue with questions 21 to 50 in the same format in the next message. Ready?

You said:

yes
ChatGPT said:

Perfect! Here's the continuation from Question 21 to 50 with options, answers, and explanations:

21. What will be the output?


python
CopyEdit
s = {1, 2, 3, 3, 2, 4, 5, 5}
print(s)

A. {1, 2, 3, 3, 4, 5}
B. [1, 2, 3, 4, 5]
C. {1, 2, 3, 4, 5}
D. Error

✅Answer: C
➡✅Sets store only unique elements.

22. What will be the output?


python
CopyEdit
a = {'Hello': 'World', 'First': 1}
b = {val: k for k, val in a.items()}
print(b)
A. {'Hello': 'World', 'First': 1}
B. {'World': 'Hello', 1: 'First'}
C. {'World': 'First', 1: 'Hello'}
D. Error

✅Answer: B
➡✅Key-value pairs are reversed using dictionary comprehension.

23. Which function converts a date string to time in Python?

A. datetime()
B. strftime()
C. strptime()
D. time()

✅Answer: C
➡✅strptime() parses string into datetime object.

24. What is the output?


python
CopyEdit
word = "Python Programming"
n = len(word)
word1 = word.upper()
word2 = word.lower()
converted_word = ""
for i in range(n):
if i % 2 == 0:
converted_word += word2[i]
else:
converted_word += word1[i]
print(converted_word)

A. python programming
B. PYTHON PROGRAMMING
C. pYtHoN PrOgRaMmInG
D. Error

✅Answer: C
➡✅Even-index → lowercase, odd-index → uppercase.
25. What is the output?
python
CopyEdit
a = "4, 5"
nums = a.split(',')
x, y = nums
int_prod = int(x) * int(y)
print(int_prod)

A. 20
B. 9
C. 45
D. Error

✅Answer: A
➡✅Splits string into ['4', ' 5'], trims spaces, then multiplies: 4 * 5 = 20.

26. What is the output?


python
CopyEdit
square = lambda x: x ** 2
a = []
for i in range(5):
a.append(square(i))
print(a)

A. [1, 2, 3, 4, 5]
B. [0, 1, 4, 9, 16]
C. [0, 2, 4, 6, 8]
D. Error

✅Answer: B
➡✅Lambda returns square of each i from 0 to 4.

27. What is the output?


python
CopyEdit
def tester(*argv):
for arg in argv:
print(arg, end=' ')
tester('Sunday', 'Monday', 'Tuesday', 'Wednesday')
A. Error
B. Sunday Monday Tuesday Wednesday
C. ['Sunday', 'Monday', 'Tuesday', 'Wednesday']
D. All days in new line

✅Answer: B
➡✅*args collects multiple arguments as a tuple.

*28. What is the type of args inside function?

A. list
B. tuple
C. dictionary
D. set

✅Answer: B
➡✅*args is stored as a tuple.

29. What is the output?


python
CopyEdit
def tester(**kwargs):
for key, value in kwargs.items():
print(key, value, end=" ")
tester(Sunday=1, Monday=2)

A. Sunday Monday
B. 1 2
C. Sunday 1 Monday 2
D. Error

✅Answer: C
➡✅**kwargs allows key-value pairs to be passed and iterated.

**30. What is the datatype of kwargs inside a function?

A. tuple
B. list
C. dictionary
D. set
✅Answer: C
➡✅**kwargs is a dictionary.

31. Which block is always executed regardless of exception?

A. try
B. except
C. finally
D. else

✅Answer: C
➡✅finally block always executes.

32. What is the output?


python
CopyEdit
from math import *
a = 2.19
b = 3.999999
c = -3.30
print(int(a), floor(b), ceil(c), fabs(c))

A. 2 3 -3 3.3
B. 2 4 -3 3.3
C. 2 3 -4 3.3
D. Error

✅Answer: C
➡✅int(2.19)=2, floor(3.999999)=3, ceil(-3.3)=-3, fabs(-3.3)=3.3

33. What is the output?


python
CopyEdit
set1 = {1, 3, 5}
set2 = {2, 4, 6}
print(len(set1 + set2))

A. 6
B. 3
C. 0
D. Error

✅Answer: D
➡✅+ operator not supported for sets — raises TypeError.

34. What keyword is used to raise an exception?

A. raise
B. throw
C. error
D. assert

✅Answer: A
➡✅raise is the correct keyword to throw exceptions.

35. What is the output?


python
CopyEdit
s1 = {1, 2, 3, 4, 5}
s2 = {2, 4, 6}
print(s1 ^ s2)

A. {1, 3, 5, 6}
B. {2, 4}
C. {1, 2, 3, 4, 5, 6}
D. Error

✅Answer: A
➡✅^ returns symmetric difference.

36. Which is not a valid set operation?

A. union
B. intersection
C. subtraction
D. division
✅Answer: D
➡✅Division / is not a valid set operation.

37. What is the output?


python
CopyEdit
a = [1, 2, 3, 4]
b = [3, 4, 5, 6]
c = [x for x in a if x not in b]
print(c)

A. [1, 2]
B. [3, 4]
C. [5, 6]
D. []

✅Answer: A
➡✅Filters elements in a that are not in b.

38. Which of the following is a valid escape sequence?

A. \n
B. \t
C. \
D. All of the above

✅Answer: D
➡✅All are valid escape sequences.

39. Which of the following is a valid string function?

A. upper()
B. split()
C. find()
D. All of the above

✅Answer: D
➡✅All listed are valid string methods.
40. Which module is required for date-time operations?

A. datemodule
B. timecalc
C. datetime
D. calendar

✅Answer: C
➡✅datetime is standard module for date/time.

41. How can assertions be disabled in Python?

A. Using pass
B. With ignore_errors
C. By running with -O flag
D. try block

✅Answer: C
➡✅Use python -O script.py to disable assertions.

42. What is the output?


python
CopyEdit
a = [[], "abc", [0], 1, 0]
print(list(filter(bool, a)))

A. ['abc', [0], 1, 0]
B. ['abc', [0], 1]
C. [[], 'abc', [0], 1, 0]
D. Error

✅Answer: B
➡✅filter(bool, a) removes falsy values: [] and 0.

43. Python is written in which language?


A. C
B. Java
C. Python
D. C++

✅Answer: A
➡✅CPython — main implementation — is written in C.

44. Evaluate: 2 ** 3 + 5 ** 2

A. 33
B. 25
C. 35
D. 64

✅Answer: A
➡✅2³ = 8, 5² = 25 ⇒ 8 + 25 = 33

45. Output?
python
CopyEdit
count = 0
while(True):
if count % 3 == 0:
print(count, end=" ")
if(count > 15):
break
count += 1

A. 0 3 6 9 12 15
B. 0 3 6 9 12 15 18
C. Infinite loop
D. 0 3 6 9 12 15 18 21

✅Answer: A
➡✅Prints multiples of 3 till 15.

46. Which of these is NOT a Python feature?


A. Object-oriented
B. Pointers
C. Interpreted
D. High-level

✅Answer: B
➡✅Python does not support pointers.

47. What does the function compute?


python
CopyEdit
def solve(a, b):
return b if a == 0 else solve(b % a, a)
print(solve(20, 50))

A. 10
B. 20
C. 5
D. 50

✅Answer: A
➡✅Computes GCD recursively using Euclid’s algorithm.

48. What is the output?


python
CopyEdit
def func():
global value
value = "Local"
value = "Global"
func()
print(value)

A. Global
B. Local
C. Error
D. None

✅Answer: B
➡✅Global variable value is modified inside function.
49. What is the output?
python
CopyEdit
def solve(a):
a = [1, 3, 5]
a = [2, 4, 6]
print(a)
solve(a)
print(a)

A. [1, 3, 5], [1, 3, 5]


B. [2, 4, 6], [1, 3, 5]
C. [2, 4, 6], [2, 4, 6]
D. Error

✅Answer: C
➡✅Lists are passed by object reference. Reassignment inside function doesn't affect outer list.

50. Which of the following are used in exception handling?

A. try
B. except
C. finally
D. All of the above

✅Answer: D
➡✅All are part of Python’s exception handling model.

You might also like