مولّد عام

اختبار #5149

❓ Mastering Python 'if' In Spyder

10 سؤال
Test your practical knowledge of Python's conditional statements (`if`, `elif`, `else`) and related operators. This quiz is perfect for beginners and intermediate Pythonistas using the Spyder IDE.
تقدّم النتيجة
0 صحيحة من 10
تمت الإجابة على 0 من 10
السؤال 1
Which syntax correctly defines a basic 'if' statement in Python?
A. if condition:
B. if (condition)
C. if condition then:
D. if condition {
السؤال 2
In Python, what is the primary role of indentation within an 'if' block?
A. It improves code readability for other developers.
B. It marks the end of the 'if' block.
C. It defines the scope of the code block belonging to the 'if' statement.
D. It is optional for single-line statements within an 'if' block.
السؤال 3
When you need to check multiple conditions sequentially in Python, which keyword is used after an 'if' statement but before a final 'else'?
A. then
B. elif
C. or if
D. case
السؤال 4
Which of the following comparison operators checks if two values are *not equal*?
A. ==
B. >=
C. <
D. !=
السؤال 5
Consider the following condition: `x > 5 and y < 10`. For this compound condition to evaluate to `True`, what must be true?
A. Both `x > 5` and `y < 10` must be `True`.
B. Only `x` must be greater than 5.
C. Either `x > 5` or `y < 10` must be `True`.
D. Only `y` must be less than 10.
السؤال 6
What will be the output of the following Python code executed in Spyder's console? ```python a = 10 b = 5 if a > 12 or b < 7: print("Condition Met") else: print("Condition Not Met") ```
A. Condition Not Met
B. Condition Met
C. Error
D. Nothing is printed
السؤال 7
What will be the output of this nested 'if' Python snippet? ```python value = 20 if value > 10: if value % 2 == 0: print("Even and Large") else: print("Odd and Large") else: print("Small") ```
A. Small
B. Odd and Large
C. Even and Large
D. Error: Indentation
السؤال 8
In a Python 'if' statement, which of the following values is considered "falsy" (evaluates to `False`)?
A. 1
B. True
C. [1, 2]
D. "" (an empty string)
السؤال 9
You run the following code in Spyder and get a `SyntaxError: invalid syntax`. Where is the likely issue? ```python x = 10 if x = 10: print("x is ten") ```
A. The `print` statement is indented incorrectly.
B. The comparison operator should be `==` not `=`.
C. You cannot assign a value inside an `if` condition.
D. The variable `x` was not declared before being used.
السؤال 10
Which of the following is an example of a Python ternary operator, providing a concise 'if-else' in one line?
A. `result = "Pass" if score >= 60 else "Fail"`
B. `if score >= 60 then result = "Pass" else "Fail"`
C. `result = (score >= 60) ? "Pass" : "Fail"`
D. `result = "Pass" unless score < 60`
الموجّه: Create practical quiz about if conditional in spyder