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.
Poengfremgang1 forsøk
0 av 10 riktige
0 av 10 besvart
Spørsmål 1
Which syntax correctly defines a basic 'if' statement in Python?
A.if condition:
B.if (condition)
C.if condition then:
D.if condition {
Spørsmål 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.
Spørsmål 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
Spørsmål 4
Which of the following comparison operators checks if two values are *not equal*?
A.==
B.>=
C.<
D.!=
Spørsmål 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.
Spørsmål 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
Spørsmål 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
Spørsmål 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)
Spørsmål 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.
Spørsmål 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`
📊
Quiz fullført!
0/ 10
0%
Completed in 1 tries
💪 Fortsett å prøve! Øvelse gjør mester!
Ledetekst: Create practical quiz about if conditional in spyder
Dette nettstedet bruker informasjonskapsler for essensielle funksjoner, andre funksjoner og for statistiske formål. Se retningslinjer for informasjonskapsler for detaljer.