This quiz will test your understanding of Basic Syntax, Conditional Statements, and Loops in Python. Each question includes multiple-choice options, and answers are provided with explanations.
- A:
variable_name = value
- B:
var variable_name = value
- C:
variable = value;
- D:
None of the above
x = 3
if x > 2:
print("Greater than 2")
else:
print("Less than or equal to 2")
- A:
Greater than 2
- B:
Less than or equal to 2
- C:
Error
- D:
None
- A: To execute a block of code only if a condition is True
- B: To execute a block of code only if a condition is False
- C: To execute a block of code unconditionally
- D: To execute a block of code multiple times
- A:
/* This is a comment */
- B:
# This is a comment
- C:
// This is a comment
- D:
<! This is a comment !>
x = 5
y = 2
result = x * (y + 3)
print(result)
- A:
25
- B:
20
- C:
15
- D:
Error
- A:
continue
- B:
break
- C:
pass
- D:
stop
- A:
a == b
- B:
a = b
- C:
a != b
- D:
a is b
- A:
str
- B:
int
- C:
float
- D:
list
for i in range(4):
print(i)
- A:
1 2 3 4
- B:
0 1 2 3 4
- C:
0 1 2 3
- D:
None
num = 11
is_prime = True
for i in range(2, num):
if num % i == 0:
is_prime = False
break
print(is_prime)
- A:
True
- B:
False
- C:
Error
- D:
None
import math
num = 4
print(math.factorial(num))
- A:
24
- B:
12
- C:
4
- D:
Error
This test ensures comprehensive coverage of Python basics, with a focus on syntax, conditional statements, and loops. 😊