Quizzma Latest Questions

What will be the output of the following code? for i in range(3): if i > 2: break else: print(i) count = 0 if count < 10: for i in range(3): print(count) count = count + 1 count = 10 for i in range(3): if count > 0: print(i) else: print(count)

for i in range(3):
if i > 2:
break
else:
print(i)

count = 0
if count < 10: for i in range(3): print(count) count = count + 1 count = 10 for i in range(3): if count > 0:
print(i)
else:
print(count)




Leave an answer

Leave an answer

What is the capital of Egypt? ( Cairo )

1 Answer

  1. Let’s break down the code step by step.

    1. First Loop:

    
    

    for i in range(3):

    if i > 2:

    break

    else:

    print(i)

    ```

    - This loop iterates through `0`, `1`, and `2`.

    - Since `i` never exceeds `2`, the `break` statement is never executed, and it prints:

    ```

    0

    1

    2

    2. Second Loop:

    “`python

    count = 0

    if count < 10:

    for i in range(3):

    print(count)

    count = count + 1

    “`

    – `count` starts at `0`, which is less than `10`, so the loop runs three times.

    – It prints the current value of `count` (`0`, then increments by `1` after each print):

    “`

    0

    1

    2

    3. Third Loop:

    “`python

    count = 10

    for i in range(3):

    if count > 0:

    print(i)

    else:

    print(count)

    – Here, `count` starts at `10`, and since `count` is greater than `0`, it will print the value of `i` (`0`, `1`,

Related Questions