0% found this document useful (0 votes)
4 views15 pages

Robolution Programming Reviewer 1 Python Basics

The document provides a series of questions and answers related to basic Python programming concepts, including function definitions, data types, control structures, and error handling. Each question is followed by multiple-choice answers, with explanations for why each option is correct or incorrect. The document serves as a quiz or study guide for beginners learning Python.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views15 pages

Robolution Programming Reviewer 1 Python Basics

The document provides a series of questions and answers related to basic Python programming concepts, including function definitions, data types, control structures, and error handling. Each question is followed by multiple-choice answers, with explanations for why each option is correct or incorrect. The document serves as a quiz or study guide for beginners learning Python.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

PYTHON PROGRAMMING – BASIC CONCEPTS

1. What is the correct way to define a function in Python?


A) function myFunc():
B) def myFunc:
C) def myFunc():
D) function: myFunc()
Answer: C
 A) Incorrect: function is not a Python keyword.
 B) Incorrect: Missing parentheses () at the end.
✅ C) Correct: Python functions are defined with def and must include parentheses.
 D) Incorrect: Wrong syntax entirely.
2. What is the output of the following code?
print("5" + "3")
A) 8
B) 53
C) Error
D) 5 3
Answer: B
 A) Incorrect: Python does not perform arithmetic on strings.
✅ B) Correct: The + operator concatenates strings.
 C) Incorrect: No syntax error here.
 D) Incorrect: There's no space between "5" and "3".
3. Which of the following is a correct Python comment?
A) // this is a comment
B) /* comment */
C) # This is a comment
D) -- comment
Answer: C
 A) Incorrect: // is used in other languages like JavaScript.
 B) Incorrect: This is C-style commenting.
✅ C) Correct: Python uses # for single-line comments.
 D) Incorrect: -- is not a comment symbol in Python.
4. What is the output of the following?
x = 5
print(x == 5)
A) 5
B) True
C) False
D) Error
Answer: B
 A) Incorrect: The expression evaluates to a boolean.
✅ B) Correct: == checks for equality.
 C) Incorrect: x is equal to 5, so this is not false.
 D) Incorrect: The syntax is correct.
5. What will this code print?
def greet():
return "Hello"
print(greet())
A) greet
B) Hello
C) None
D) Error
Answer: B
 A) Incorrect: It returns the result, not the function name.
✅ B) Correct: return gives back the string "Hello", and print outputs it.
 C) Incorrect: It does return something, not None.
 D) Incorrect: No syntax error exists.
6. What does this code do?
for i in range(3):
print(i)
A) Prints 1 to 3
B) Prints 0 to 2
C) Prints 1 to 2
D) Error
Answer: B
 A) Incorrect: range(3) starts at 0 and stops before 3.
✅ B) Correct: Output will be 0, 1, 2.
 C) Incorrect: It includes 0.
 D) Incorrect: No syntax issues.
7. Which of the following data types is immutable in Python?
A) List
B) Dictionary
C) Set
D) String
Answer: D
 A) Incorrect: Lists can be modified.
 B) Incorrect: Dictionaries are mutable.
 C) Incorrect: Sets are mutable.
✅ D) Correct: Strings cannot be changed once created.
8. What is the purpose of the elif keyword in Python?
A) Ends the if statement
B) Repeats the if block
C) Adds an additional condition
D) Declares a loop
Answer: C
 A) Incorrect: elif does not end, but extends the condition.
 B) Incorrect: Repeating would require a loop.
✅ C) Correct: elif allows multiple condition checks.
 D) Incorrect: Loops are defined using for or while.
9. What is wrong with this code?
if x = 10:
print("x is 10")
A) Nothing is wrong
B) print is indented wrong
C) = should be ==
D) if can't be used here
Answer: C
 A) Incorrect: There is a syntax error.
 B) Incorrect: Indentation is okay.
✅ C) Correct: = is assignment; == is comparison.
 D) Incorrect: if is valid syntax.
10. What is the output of this function call?
def add(a, b=2):
return a + b
print(add(3))
A) 5
B) Error
C) 3
D) 6
Answer: A
 A) ✅ Correct: Default value for b is used, so 3 + 2 = 5
 B) Incorrect: No error here
 C) Incorrect: That would ignore b
 D) Incorrect: That’s if b=3
11. What is the output of this code?
print(type(5.0))
A) <class 'int'>
B) <class 'float'>
C) <class 'str'>
D) float
Answer: B
 A) Incorrect: 5.0 is not an integer.
✅ B) Correct: 5.0 is a float; type() confirms it.
 C) Incorrect: No strings involved.
 D) Incorrect: type() returns the full class name, not just float.
12. What does this line do?
name = input("Enter your name: ")
A) Declares a constant
B) Outputs the name
C) Accepts user input and stores it in name
D) Converts name to uppercase
Answer: C
 A) Incorrect: name is a variable, not a constant.
 B) Incorrect: It doesn’t print anything.
✅ C) Correct: input() gets user input and assigns it to name.
 D) Incorrect: No .upper() used here.
13. Which of the following is a valid Python variable name?
A) 2cool
B) cool_2
C) cool-2
D) class
Answer: B
 A) Incorrect: Variables cannot start with numbers.
✅ B) Correct: cool_2 is a valid variable name.
 C) Incorrect: Hyphens are not allowed in variable names.
 D) Incorrect: class is a reserved keyword in Python.
14. What does this code print?
print(bool(""))
A) True
B) False
C) ""
D) None
Answer: B
 A) Incorrect: An empty string is considered false.
✅ B) Correct: bool("") returns False.
 C) Incorrect: The bool() function returns a Boolean, not a string.
 D) Incorrect: None is a different type of value.
15. What is the output of the following code?
a = 10
b = 3
print(a // b)
A) 3.33
B) 3
C) 3.0
D) 4
Answer: B
 A) Incorrect: This would be true for regular division /.
✅ B) Correct: // is integer division, dropping the decimal.
 C) Incorrect: // returns an int in this case.
 D) Incorrect: 10 divided by 3 is not 4.
16. What does this function return?
def double(x):
return x * 2
print(double("Hi"))
A) 4
B) Error
C) HiHi
D) "Hi"
Answer: C
 A) Incorrect: Multiplication is not numeric here.
 B) Incorrect: Python allows string repetition with *.
✅ C) Correct: "Hi" * 2 results in "HiHi".
 D) Incorrect: It returns a modified string, not the original.
17. What will happen if you run this code?
x = 10
if x > 5
print("x is greater than 5")
A) It will print the message
B) It will raise a runtime error
C) It will raise a syntax error
D) Nothing happens
Answer: C
 A) Incorrect: It won't run due to syntax error.
 B) Incorrect: It’s a syntax issue, not runtime.
✅ C) Correct: Missing colon : causes a syntax error.
 D) Incorrect: Code does not execute silently.
18. What is the correct way to loop over a list?
items = ["a", "b", "c"]
A) for x from items:
B) foreach x in items:
C) for x in items:
D) loop x in items:
Answer: C
 A) Incorrect: from is not a valid loop keyword in Python.
 B) Incorrect: foreach is not used in Python.
✅ C) Correct: for x in items: is valid syntax.
 D) Incorrect: loop is not a Python keyword.
19. What does this code print?
print(len("hello world"))
A) 10
B) 11
C) 12
D) Error
Answer: B
 A) Incorrect: It misses the space.
✅ B) Correct: Includes 5 letters in "hello", 1 space, and 5 letters in "world".
 C) Incorrect: Too many characters counted.
 D) Incorrect: No error in this line.
20. Which line will cause an error in Python?
A) x = 10
B) print("Hi")
C) if x == 10:
D) for i = 0 to 5:
Answer: D
 A) Incorrect: This is a valid variable assignment.
 B) Incorrect: Valid print() statement.
 C) Incorrect: Valid conditional syntax.
✅ D) Correct: for i = 0 to 5: is not valid Python syntax. Use range() instead.
21. What is the output of this code?
x = [1, 2, 3]
x.append(4)
print(x)
A) [1, 2, 3, 4]
B) [1, 2, 3]
C) 4
D) [4, 3, 2, 1]
Answer: A
 ✅ A) Correct: append(4) adds 4 to the end of the list.
 B) Incorrect: That’s the list before appending.
 C) Incorrect: That’s just the value being added, not the result.
 D) Incorrect: The list is not reversed.
22. What is the output of the following function call?
def identity(x):
return x
print(identity(7))
A) x
B) 7
C) None
D) Error
Answer: B
 A) Incorrect: The value of x is returned, not the variable itself.
✅ B) Correct: identity(7) returns 7.
 C) Incorrect: It has a return value, so not None.
 D) Incorrect: No error in this simple function.

23. Which Python keyword is used to handle exceptions?


A) error
B) catch
C) try
D) fault
Answer: C
 A) Incorrect: error is not a keyword.
 B) Incorrect: catch is used in other languages like Java, not Python.
✅ C) Correct: Python uses try along with except.
 D) Incorrect: fault is not a keyword in Python.

24. What is the result of this expression?


5 % 2
A) 2.5
B) 0
C) 2
D) 1
Answer: D
 A) Incorrect: That’s division, not modulo.
 B) Incorrect: 5 is not evenly divisible by 2.
 C) Incorrect: That’s the quotient, not the remainder.
✅ D) Correct: Modulo gives the remainder of 5 ÷ 2, which is 1.

25. What is the result of this expression?


True and False
A) True
B) False
C) None
D) Error
Answer: B
 A) Incorrect: and requires both to be True.
✅ B) Correct: True and False evaluates to False.
 C) Incorrect: No None value is involved.
 D) Incorrect: No error in Boolean logic.

26. What is the correct way to start a while loop in Python?


A) while (x > 0) {
B) while x > 0:
C) while x > 0 then
D) loop while x > 0:
Answer: B
 A) Incorrect: This uses C/Java syntax with braces.
✅ B) Correct: Python uses colons and indentation, not braces.
 C) Incorrect: then is not used in Python.
 D) Incorrect: loop while is not valid Python syntax.

27. What is printed by this code?


x = 3
x *= 2
print(x)
A) 6
B) 3
C) 5
D) 2
Answer: A
 ✅ A) Correct: x *= 2 multiplies x by 2 → 3 × 2 = 6.
 B) Incorrect: That’s the original value of x.
 C) Incorrect: No such operation results in 5.
 D) Incorrect: 2 is not related here.
28. Which line will cause a runtime error (not syntax)?
A) print("Hello")
B) x = 10 / 0
C) if x == 10:
D) x = 5
Answer: B
 A) Incorrect: This line just prints a string.
✅ B) Correct: Division by zero causes a runtime error.
 C) Incorrect: This is valid syntax and logic.
 D) Incorrect: Assigning a number is valid.

29. Which of the following is a function definition?


A) def = myFunction():
B) function myFunction():
C) define myFunction()
D) def myFunction():
Answer: D
 A) Incorrect: def = is invalid syntax.
 B) Incorrect: Python does not use the function keyword.
 C) Incorrect: define is not a Python keyword.
✅ D) Correct: Python uses def followed by function name and parentheses.

30. What will this code output?


for i in range(1, 4):
print(i, end="-")
A) 1-2-3-4-
B) 1-2-3-
C) 0-1-2-
D) 1 2 3
Answer: B
 A) Incorrect: range(1, 4) excludes 4.
✅ B) Correct: Outputs 1-2-3- without newline, due to end="-".
 C) Incorrect: Starts from 0 only if range(0, …)
 D) Incorrect: That would be default print spacing, not custom separator.

31. What will this code output?


print("7" * 3)
A) 21
B) 777
C) 10
D) Error
Answer: B
 A) Incorrect: That’s numeric multiplication, not string repetition.
✅ B) Correct: Strings can be repeated using *, so "7" * 3 = "777".
 C) Incorrect: No math operation is being done here.
 D) Incorrect: Python allows string * integer.

32. What is the result of this expression?


4 + 3 * 2
A) 14
B) 10
C) 16
D) 12
Answer: B
 A) Incorrect: Ignores order of operations.
✅ B) Correct: Multiplication happens first → 3 * 2 = 6; then 4 + 6 = 10.
 C) Incorrect: Likely confusion from 4 + 3 = 7, 7 * 2 = 14 (wrong order).
 D) Incorrect: There’s no combination that yields 12 here.

33. What is wrong with this function?


def sayHello()
print("Hello")
A) Missing return
B) print is invalid
C) Missing colon :
D) Nothing is wrong
Answer: C
 A) Incorrect: A function doesn’t need return.
 B) Incorrect: print is valid.
✅ C) Correct: Function definition needs a colon at the end.
 D) Incorrect: There is a syntax error.

34. What will this output?


list1 = [1, 2, 3]
print(len(list1))
A) 2
B) 3
C) [1, 2, 3]
D) Error
Answer: B
 A) Incorrect: That’s one element short.
✅ B) Correct: The list has three items. len() returns 3.
 C) Incorrect: That’s the list itself, not its length.
 D) Incorrect: No error here.

35. What does the break statement do in a loop?


A) Skips the current iteration
B) Exits the loop entirely
C) Ends the function
D) Starts a new loop
Answer: B
 A) Incorrect: That’s continue.
✅ B) Correct: break exits the loop immediately.
 C) Incorrect: return ends a function.
 D) Incorrect: No loop restarts with break.

36. What is the output of this code?


x = [1, 2]
y = x
y.append(3)
print(x)
A) [1, 2]
B) [1, 2, 3]
C) [3]
D) Error
Answer: B
 A) Incorrect: The list was modified through y, which points to the same object.
✅ B) Correct: Both x and y refer to the same list, so changes reflect in both.
 C) Incorrect: That’s not how lists behave.
 D) Incorrect: There’s no error.

37. What does this function do?


def square(x):
return x * x
A) Divides x by itself
B) Adds x to x
C) Returns the square of x
D) Multiplies x by 2
Answer: C
 A) Incorrect: That would be x / x
 B) Incorrect: That would be x + x
✅ C) Correct: Multiplying x by itself returns the square.
 D) Incorrect: That would be x * 2
38. Which of the following is NOT a Python data type?
A) tuple
B) set
C) array
D) list
Answer: C
 A) Incorrect: tuple is a valid data type.
 B) Incorrect: set is also valid.
✅ C) Correct: Python does not have a native array type like other languages; lists are used
instead.
 D) Incorrect: list is one of the main types.

39. What will this output?


for i in range(2):
for j in range(2):
print(i, j)
A) (0,0), (1,1)
B) (0,0), (0,1), (1,0), (1,1)
C) (1,1), (2,2)
D) Error
Answer: B
 A) Incorrect: That’s a subset only.
✅ B) Correct: Nested loops generate all pair combinations.
 C) Incorrect: range(2) only includes 0 and 1.
 D) Incorrect: No syntax error here.

40. What is the purpose of indentation in Python?


A) Makes code look pretty
B) Declares variables
C) Defines code blocks
D) Comments out code
Answer: C
 A) Incorrect: It's not just aesthetic.
 B) Incorrect: Variables are not defined by indentation.
✅ C) Correct: Python uses indentation to define blocks like loops, functions, conditionals.
 D) Incorrect: # is used for comments, not indentation.

41. What is the output of this code?


print(type([1, 2, 3]))
A) <class 'list'>
B) <type 'array'>
C) [1, 2, 3]
D) list
Answer: A
 ✅ A) Correct: type() returns the full class name. Lists are of class list.
 B) Incorrect: Python doesn’t use <type 'array'> for lists.
 C) Incorrect: That’s the list itself, not its type.
 D) Incorrect: Not the complete output of type().

42. What does this expression evaluate to?


bool(0)
A) 0
B) True
C) False
D) Error
Answer: C
 A) Incorrect: bool() returns a boolean, not the original number.
 B) Incorrect: 0 is interpreted as False in Boolean context.
✅ C) Correct: bool(0) evaluates to False.
 D) Incorrect: No error here.
43. What is the correct way to define a list in Python?
A) list = (1, 2, 3)
B) list = [1, 2, 3]
C) list = {1, 2, 3}
D) list = <1, 2, 3>
Answer: B
 A) Incorrect: That creates a tuple, not a list.
✅ B) Correct: Square brackets define lists.
 C) Incorrect: Curly braces define a set.
 D) Incorrect: < > is invalid for defining collections.

44. What is the value of x after this code runs?


x = 5
x = x + 1
A) 6
B) 10
C) 5
D) 1
Answer: A
 ✅ A) Correct: x is increased by 1, so 5 + 1 = 6.
 B) Incorrect: No doubling occurred.
 C) Incorrect: x is changed.
 D) Incorrect: It wasn’t reset to 1.

45. Which line correctly checks if x is not equal to 3?


A) if x =! 3:
B) if x != 3:
C) if x not = 3:
D) if x <> 3:
Answer: B
 A) Incorrect: =! is not valid syntax.
✅ B) Correct: != is the correct not-equal operator.
 C) Incorrect: not = is invalid.
 D) Incorrect: <> was used in Python 2, not Python 3.

46. What will this code print?


for i in range(0, 6, 2):
print(i)
A) 0 2 4 6
B) 2 4 6
C) 0 2 4
D) 1 3 5
Answer: C
 A) Incorrect: range(0, 6, 2) excludes 6.
 B) Incorrect: 0 is included in the range.
✅ C) Correct: Starts at 0, steps by 2 → 0, 2, 4
 D) Incorrect: That would be range(1, 6, 2)

47. What will this print?


x = "abc"
print(x[1])
A) a
B) b
C) c
D) 1
Answer: B
 A) Incorrect: Index 0 holds "a"
✅ B) Correct: Strings are 0-indexed, so index 1 is "b"
 C) Incorrect: That’s index 2
 D) Incorrect: Not numeric indexing output

48. What is the output of this expression?


3 ** 2
A) 5
B) 6
C) 9
D) 8
Answer: C
 A) Incorrect: That’s 3 + 2
 B) Incorrect: That’s 3 × 2
✅ C) Correct: ** is exponentiation → 3² = 9
 D) Incorrect: That’s 2³

49. Which of the following is a valid if statement?


A) if x == 10 then:
B) if (x == 10)
C) if x == 10:
D) if x = 10:
Answer: C
 A) Incorrect: then is not used in Python.
 B) Incorrect: Missing colon :
✅ C) Correct: Proper syntax for if in Python.
 D) Incorrect: = is assignment, not comparison.

50. What does this code do?


print("Python"[::-1])
A) Prints “Python” normally
B) Prints “nohtyP”
C) Causes an error
D) Removes spaces
Answer: B
 A) Incorrect: It reverses the string.
✅ B) Correct: [::-1] is slice notation to reverse strings.
 C) Incorrect: Syntax is valid.
 D) Incorrect: It doesn’t modify spacing.

51. What does the following expression return?


len("Python") > 4
A) 6
B) True
C) False
D) Error
Answer: B
 A) Incorrect: len() returns 6, but the full expression evaluates to a Boolean.
✅ B) Correct: len("Python") is 6 → 6 > 4 → True.
 C) Incorrect: 6 is greater than 4, so it’s not false.
 D) Incorrect: There’s no error in the code.

52. What is the output of this code?


a = "3"
b = int(a)
print(b + 2)
A) 32
B) 5
C) Error
D) 3
Answer: B
 A) Incorrect: That would happen if it were string concatenation.
✅ B) Correct: int("3") converts to integer, 3 + 2 = 5.
 C) Incorrect: No error in type conversion.
 D) Incorrect: That’s the value before adding 2.

53. What does the following function return?


def mystery(x):
return x % 2 == 0
A) True if x is even
B) False for all x
C) The remainder when x is divided by 2
D) x divided by 2
Answer: A
 ✅ A) Correct: The expression checks if x is divisible by 2 → even number.
 B) Incorrect: It returns False only when x is odd.
 C) Incorrect: That would be just x % 2
 D) Incorrect: x / 2 is not used here.

54. What will this code print?


x = [10, 20, 30]
print(x[-1])
A) 10
B) 30
C) -1
D) Error
Answer: B
 A) Incorrect: That’s index 0.
✅ B) Correct: Index -1 refers to the last element in the list.
 C) Incorrect: That’s the index used, not the output.
 D) Incorrect: Negative indexing is valid in Python.

55. What does input() always return?


A) Integer
B) Float
C) Boolean
D) String
Answer: D
 A) Incorrect: You must convert input to integer with int().
 B) Incorrect: Same with float; needs explicit conversion.
 C) Incorrect: Input isn’t Boolean by default.
✅ D) Correct: input() always returns a string unless explicitly converted.

56. What is wrong with this code?


for i in range(5)
print(i)
A) The loop variable is incorrect
B) The range is invalid
C) Missing colon :
D) print cannot be inside a loop
Answer: C
 A) Incorrect: i is valid.
 B) Incorrect: range(5) is valid.
✅ C) Correct: for loops in Python require a colon at the end.
 D) Incorrect: print can be used in loops.

57. What will this code print?


x = [1, 2, 3]
x[1] = 99
print(x)
A) [1, 2, 3]
B) [1, 99, 3]
C) [99, 2, 3]
D) Error
Answer: B
 A) Incorrect: The second item was modified.
✅ B) Correct: Index 1 was changed from 2 to 99.
 C) Incorrect: Only index 1 was modified, not index 0.
 D) Incorrect: The assignment is valid.

58. Which operator is used for floor division?


A) /
B) //
C) %
D) **
Answer: B
 A) Incorrect: / is regular division.
✅ B) Correct: // is floor division — rounds down to nearest whole number.
 C) Incorrect: % is modulo (remainder).
 D) Incorrect: ** is exponentiation.

59. What is the output of this code?


print("Hello\nWorld")
A) Hello World
B) Hello\nWorld
C) Hello
World
D) Error
Answer: C
 A) Incorrect: The \n causes a line break.
 B) Incorrect: The escape character is interpreted, not printed.
✅ C) Correct: \n is a newline character, so "World" goes to the next line.
 D) Incorrect: No syntax error exists.

60. Which line will cause a type error in Python?


A) print("5" + "3")
B) print(5 + 3)
C) print("5" + 3)
D) print(int("5") + 3)
Answer: C
 A) Incorrect: Concatenates two strings.
 B) Incorrect: Adds two integers.
✅ C) Correct: Cannot add a string and an integer directly — causes TypeError.
 D) Incorrect: Converts string to int before addition.

71. What is the output of the following code?


x = [1, 2, 3]
print(x[-1])
A) 1
B) 2
C) 3
D) Error
Answer: C
 A: Incorrect – this is the first item, not the last.
 B: Incorrect – this is the second item.
 ✅ C: Correct – x[-1] accesses the last element of the list.
 D: Incorrect – negative indexing is valid in Python.

72. Which keyword is used to define a function in Python?


A) function
B) define
C) def
D) fun
Answer: C
 A: Incorrect – not a valid Python keyword.
 B: Incorrect – define is not used in Python.
 ✅ C: Correct – def is the correct syntax for defining functions.
 D: Incorrect – not a reserved word in Python.
73. What will be the output of this code?
def add(a, b=3):
return a + b

print(add(2))
A) 2
B) 3
C) 5
D) Error
Answer: C
 A: Incorrect – this is just the value of a.
 B: Incorrect – b=3, but a=2 is also added.
 ✅ C: Correct – 2 + 3 = 5.
 D: Incorrect – no syntax or runtime error occurs.
74. What type of error is raised when you try to access a variable that hasn’t been defined?
A) SyntaxError
B) NameError
C) TypeError
D) ValueError
Answer: B
 A: Incorrect – this occurs due to wrong syntax, not undefined names.
 ✅ B: Correct – accessing an undefined variable causes a NameError.
 C: Incorrect – occurs when an operation uses an inappropriate type.
 D: Incorrect – happens when a function receives a value of the correct type but inappropriate content.
75. What will be printed by the following code?
for i in range(2):
for j in range(2):
print(i + j, end=" ")
A) 0 1 1 2
B) 0 1 0 1
C) 0 1 2 3
D) 0 0 1 1
Answer: A
 ✅ A: Correct – Iterates over (0+0), (0+1), (1+0), (1+1) → 0 1 1 2
 B: Incorrect – j is changing, not fixed at 1.
 C: Incorrect – values don’t go beyond 2.
 D: Incorrect – these are not the sums of i + j.
76. What is the result of the following code?
print(bool(0), bool(1), bool(-1))
A) False True False
B) True False True
C) False True True
D) False False True
Answer: C
 A: Incorrect – -1 is also truthy.
 B: Incorrect – 0 is False.
 ✅ C: Correct – only 0 is False; non-zero values are True.
 D: Incorrect – 1 is not False.

77. Which of the following data types is immutable in Python?


A) List
B) Dictionary
C) Set
D) Tuple
Answer: D
 A: Incorrect – lists can be changed.
 B: Incorrect – dictionaries are mutable.
 C: Incorrect – sets can be modified.
 ✅ D: Correct – tuples cannot be modified after creation.

78. Which of the following will cause an error in Python?


x = "5"
y = 2
print(x * y)
A) Error
B) 55
C) 555
D) No error, output: 55
Answer: D
 A: Incorrect – string * integer is valid.
 B: Incorrect – this would be true if y = 2 and x = 5 as an int.
 C: Incorrect – x * 3 would be 555.
 ✅ D: Correct – "5" * 2 results in "55".
79. What is the output of this function call?
def greet(name="World"):
print("Hello,", name)

greet()
A) Hello,
B) Hello, World
C) Hello, name
D) Error
Answer: B
 A: Incorrect – name is provided as default.
 ✅ B: Correct – no argument passed, uses default "World".
 C: Incorrect – this is just the variable name.
 D: Incorrect – no syntax or runtime error.
80. What does the following code output?
x = [10, 20, 30]
x[1] = x[1] + 5
print(x)
A) [10, 25, 30]
B) [15, 20, 30]
C) [10, 20, 35]
D) Error
Answer: A
 ✅ A: Correct – x[1] = 20 + 5 → [10, 25, 30]
 B: Incorrect – x[0] remains unchanged.
 C: Incorrect – the 3rd item is not modified.
 D: Incorrect – no error occurs.
81. What will be the output of this code?
def test():
return 2 + 3 * 4

print(test())
A) 20
B) 14
C) 24
D) 9
Answer: B
 A: Incorrect – this assumes addition first, but multiplication comes first.
 ✅ B: Correct – 3 * 4 = 12, then 2 + 12 = 14.
 C: Incorrect – not the result of correct order of operations.
 D: Incorrect – not derived from this operation.
82. What is wrong with this code?
def add(x, y)
return x + y
A) Nothing is wrong
B) Missing colon after function name
C) The return statement is incorrect
D) The function has no parameters
Answer: B
 A: Incorrect – syntax error present.
 ✅ B: Correct – def add(x, y): is the correct syntax.
 C: Incorrect – return line is fine.
 D: Incorrect – function clearly has 2 parameters.
83. Which keyword is used to define a function in Python?
A) define
B) function
C) def
D) func
Answer: C
 A: Incorrect – Python doesn’t use define.
 B: Incorrect – common in pseudocode or other languages.
 ✅ C: Correct – Python uses def.
 D: Incorrect – not a valid keyword.
84. What is the value of result?
def mystery(a, b=3):
return a * b

result = mystery(4)
A) 7
B) 12
C) 3
D) None
Answer: B
 A: Incorrect – you’re multiplying, not adding.
 ✅ B: Correct – default value of b is used, 4 × 3 = 12.
 C: Incorrect – that’s just the default value, not the output.
 D: Incorrect – function returns a value.
85. What does this code output?
x = 3
y = x
x = 5
print(y)
A) 5
B) 3
C) 8
D) Error
Answer: B
 A: Incorrect – y was assigned before x changed.
 ✅ B: Correct – y = 3, and isn’t affected by x = 5 afterward.
 C: Incorrect – no addition occurs.
 D: Incorrect – this is valid code.

You might also like