Latest Update Already Passed
How do you use nested `if` statements in Python?
✔✔You can use nested `if` statements by placing an `if` statement inside another `if` block.
Example:
```python
if x > 5:
if y < 10:
print("Both conditions are True")
```
What is the result of a `while` loop with the condition `while 0` in Python?
✔✔A `while` loop with the condition `while 0` will not execute, as `0` is considered `False` in
Python.
How do you implement an infinite loop in Python?
✔✔You can implement an infinite loop using `while True:`, which will keep running until
manually stopped or a `break` is used.
1
, What is the result of the following code:
```python
x = 10
while x > 0:
x -= 1
if x == 5:
break
```
✔✔The loop will terminate when `x` equals 5, and the value of `x` will be 5.
How can you prevent an infinite loop when using `while True`?
✔✔You can use a `break` statement or include a condition within the loop to ensure it exits at
some point.
What is the purpose of a `while` loop in Python?
✔✔A `while` loop repeatedly executes a block of code as long as the given condition is `True`.
2