Explanation:
๐น Loop Statement
for i in range(4):
Runs the loop 4 times with values: 0, 1, 2, 3
๐น Even Number Check
if i % 2 == 0: continue
Checks if i is even
If true → skips the current iteration
Skipped values: 0, 2
๐น Print Statement with Condition
print(i*i if i > 1 else i+2, end=" ")
Uses a conditional (ternary) expression
➤ Condition:
If i > 1 → print i*i (square)
Else → print i+2
๐น Iteration Details
➤ i = 0
Even → skipped
➤ i = 1
Odd → processed
i > 1 → False
Output → 1 + 2 = 3
➤ i = 2
Even → skipped
➤ i = 3
Odd → processed
i > 1 → True
Output → 3 * 3 = 9
๐น Output Formatting
end=" "
Prints output on the same line
Adds a space between values
✅ Final Output
3 9

0 Comments:
Post a Comment