Skip to content

Latest commit

 

History

History
230 lines (156 loc) · 3.7 KB

TEST - Basic Syntax, Conditional Statements, and Loops.md

File metadata and controls

230 lines (156 loc) · 3.7 KB

📝 Python Fundamentals Quiz

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.


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

  • A: variable_name = value
  • B: var variable_name = value
  • C: variable = value;
  • D: None of the above
Answer

Correct Answer -> A: variable_name = value


🔁 2. What does the following Python code output?

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
Answer

Correct Answer -> A: Greater than 2


🚦 3. What is the purpose of the if statement in Python?

  • 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
Answer

Correct Answer -> A: To execute a block of code only if a condition is True


💬 4. How do you write a single-line comment in Python?

  • A: /* This is a comment */
  • B: # This is a comment
  • C: // This is a comment
  • D: <! This is a comment !>
Answer

Correct Answer -> B: # This is a comment


🧮 5. What will be the output of the following code?

x = 5
y = 2
result = x * (y + 3)
print(result)
  • A: 25
  • B: 20
  • C: 15
  • D: Error
Answer

Correct Answer -> A: 25


🔃 6. Which statement is used to exit a loop prematurely in Python?

  • A: continue
  • B: break
  • C: pass
  • D: stop
Answer

Correct Answer -> B: break


🔍 7. What is the correct syntax to check if two variables, a and b, are equal in Python?

  • A: a == b
  • B: a = b
  • C: a != b
  • D: a is b
Answer

Correct Answer -> A: a == b


📚 8. In Python, which data type is used to store a sequence of characters?

  • A: str
  • B: int
  • C: float
  • D: list
Answer

Correct Answer -> A: str


🔂 9. What will the following Python code output?

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
Answer

Correct Answer -> C: 0 1 2 3


🌟 BONUS: Prime Number Check

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
Answer

Correct Answer -> A: True


🌟 BONUS: Factorial Calculation

import math
num = 4
print(math.factorial(num))
  • A: 24
  • B: 12
  • C: 4
  • D: Error
Answer

Correct Answer -> A: 24


This test ensures comprehensive coverage of Python basics, with a focus on syntax, conditional statements, and loops. 😊