If Statements - Test

1. Which of the following is the correct syntax for an if statement?

A) if x > 10: print("x is greater than 10")
B) if (x > 10) { print("x is greater than 10") }
C) if x > 10 print "x is greater than 10"

2. What is the result of the following code?

x = 5 if x < 10:     print("Less than 10") else:     print("10 or more")
A) Less than 10
B) 10 or more
C) Error

3. Which logical operator is used to check if both conditions are true?

A) ||
B) !
C) and

4. How do you negate a condition in Python?

A) not condition
B) !condition
C) ~condition

5. Which statement is used to handle multiple conditions in Python?

A) if and else
B) if, elif and else
C) if or else

6. What is the output of the following code?

x = 10 if x > 5:     print("A") elif x > 10:     print("B") else:     print("C")
A) A
B) B
C) C