Python Basics MCQs
Section 1: Variables & Constants (Q1–Q15)
1. Which of the following is a correct way to assign a value to a variable in
Python?
A) int x = 10 B) x = 10
C) 10 = x D) variable x = 10
2. What will be the output of the following code?
x=5
print(x)
A) x B) 5
C) x=5 D) Error
3. Variable names in Python cannot start with:
A) A letter B) An underscore _
C) A number D) A lowercase letter
4. Which of these is a valid variable name in Python?
A) 2value B) value_2
C) value-2 D) value 2
5. Which data type is used to store text in Python?
A) int B) float
C) str D) bool
6. What will be the output of this code?
x = "Hello"
y = "World"
print(x + y)
A) Hello World B) HelloWorld
C) Hello+World D) Error
ICT Programming worksheet Page 1 of 9
7. Constants in Python are usually represented by:
A) CamelCase B) ALL_UPPERCASE letters
C) lowercase letters D) Starting with #
8. What is the value of x after this code executes?
x = 10
x = 20
A) 10 B) 20 C) 30 D) Error
9. Which operator is used to assign values to variables?
A) == B) = C) := D) =>
10. What will be printed by the following code?
a=5
b=a
print(b)
A) a B) 5 C) b D) Error
11. Which statement about variables in Python is correct?
A) Python requires explicit declaration of variables.
B) Python variables are created when first assigned a value.
C) Variable names cannot contain underscores.
D) Python variables must always store integers.
12. What is the default value of an uninitialized variable in Python?
A) 0 B) None C) Null D) Error
13. Which of the following statements will raise an error?
A) x = 10 B) _value = 50
C) name@ = "Ali" D) my_var2 = 5.5
14. Which of these is not a valid Python data type?
A) str B) int C) real D) bool
15. Which of the following is the correct way to define a constant by convention?
A) pi = 3.14 B) PI = 3.14
C) Pi = 3.14 D) pI = 3.14
ICT Programming worksheet Page 2 of 9
Section 2: Input & Print Statements (Q16–Q25)
16. Which function is used to take user input in Python?
A) scan() B) input() C) get() D) read()
17. What is the default data type returned by the input() function?
A) int B) str C) float D) bool
18. What will be the output of this code if the user enters 10?
num = input("Enter a number: ")
print(num + num)
A) 20 B) 1010
C) Error D) Enter a number: 10
19. Which of the following statements will print "Hello World" correctly?
A) print(Hello World) B) print("Hello World")
C) echo("Hello World") D) output("Hello World")
20. What will be printed by this code?
name = "Ali"
age = 20
print("My name is", name, "and I am", age, "years old")
A) My name is Ali and I am 20 years old
B) My name is, Ali, and I am, 20, years old
C) My name is Ali and I am 20
D) Error
21. What is the correct way to take an integer input from the user?
A) num = int(input("Enter a number: "))
B) num = input(int("Enter a number: "))
C) num = [Link]("Enter a number: ")
D) num = get(int("Enter a number: "))
ICT Programming worksheet Page 3 of 9
22. Which keyword argument in the print() function is used to specify a separator
between values?
A) end B) sep C) split D) join
23. What will be printed by the following code?
print("A", "B", "C", sep="-")
A) A B C B) A-B-C C) ABC D) A-B C
24. Which argument changes the default ending character in print()?
A) end B) finish C) sep D) stop
25. Which of the following will display text without moving to a new line?
A) print("Hello", end="") B) print("Hello")
C) [Link]("Hello") D) output("Hello")
Section 3: If Statements (Q26–Q30)
26. Which is the correct syntax for an if statement in Python?
A) if x > 5 B) if x > 5:
C) if (x > 5) D) if: x > 5
27. What will be printed by this code?
x = 10
if x > 5:
print("Greater")
A) Greater B) x > 5 C) Error D) Nothing
28. What happens if the colon : is missing in an if statement?
A) The code runs normally. B) A SyntaxError is raised.
C) The condition is ignored. D) Python automatically adds it.
29. Which of the following is a correct indentation level for code inside an if block?
A) 1 space B) 4 spaces
C) 8 spaces only D) No indentation needed
ICT Programming worksheet Page 4 of 9
30. What will be printed by this code?
a=3
if a == 3:
print("Equal")
A) Equal B) 3 C) True D) Error
Section 4: If-Else Statements (Q31–Q40)
31. What will be the output?
x=7
if x % 2 == 0:
print("Even")
else:
print("Odd")
A) Even B) Odd C) 7 D) Error
32. In an if-else statement, the else part is executed when:
A) The if condition is true. B) The if condition is false.
C) There is no if condition. D) The program ends.
33. What will be printed?
a=5
if a > 10:
print("Large")
else:
print("Small")
A) Large B) Small C) 5 D) Error
ICT Programming worksheet Page 5 of 9
34. Identify the correct structure of an if-else statement.
A) if condition: else: B) if condition else:
C)
if condition:
statement
else:
statement
D) if condition then else condition
35. What will be printed?
num = 0
if num:
print("Non-zero")
else:
print("Zero")
A) Zero B) Non-zero C) Error D) None
36. Which operator checks equality between two values?
A) = B) == C) === D) equals
37. Which of these is not allowed in an if-else condition?
A) Comparing strings B) Logical operators like and /
or
C) Multiple else statements D) Nested if statements
38. What will be printed?
age = 18
if age >= 18:
print("Adult")
else:
print("Minor")
A) Adult B) Minor C) 18 D) Error
ICT Programming worksheet Page 6 of 9
39. What does the else statement require?
A) An if statement before it B) Nothing, it can stand alone
C) A variable to be declared D) A for loop
40. Which of these keywords is used along with if to test multiple conditions?
A) elseif B) elif
C) else if D) elifelse
Section 5: If-Elif Statements (Q41–Q50)
41. Which structure correctly represents if-elif in Python?
A)
if condition:
statement
elif condition:
statement
B)
if condition:
statement
else if condition:
statement
C) if elif condition:
D) if condition elif:
42. What will be printed?
x=5
if x > 5:
print("Greater")
elif x == 5:
print("Equal")
else:
print("Smaller")
ICT Programming worksheet Page 7 of 9
A) Greater B) Equal C) Smaller D) Error
43. Which keyword is not used in an if-elif-else structure?
A) if B) elif C) else D) switch
44. How many elif blocks can you have in a single chain?
A) Only 1 B) 2 C) Unlimited D) None
45. What will be printed?
marks = 85
if marks >= 90:
print("A")
elif marks >= 80:
print("B")
else:
print("C")
A) A B) B C) C D) Error
46. What happens if none of the if or elif conditions are true and there is no else?
A) Program stops with error. B) Nothing is executed.
C) The first condition runs automatically. D) Python crashes.
47. Which of these is true about elif?
A) It can only appear once.
B) It allows checking multiple conditions without nesting.
C) It must always be followed by else.
D) It can replace if.
48. What will be printed?
num = -5
if num > 0:
print("Positive")
elif num == 0:
print("Zero")
else:
print("Negative")
ICT Programming worksheet Page 8 of 9
A) Positive B) Zero C) Negative D) Error
49. Which logical operator is used to check multiple conditions in a single if
statement?
A) && B) and C) || D) both
50. What will be printed?
x = 10
if x > 10:
print("Greater")
elif x < 10:
print("Smaller")
else:
print("Equal")
A) Greater
B) Smaller
C) Equal
D) Error
ICT Programming worksheet Page 9 of 9