QuestionQ266

VerifiedControl Flow – Conditional Blocks and Loops

What is the number of asterisk (*) characters that will be printed to the screen when the following code runs?

Question Image

Explanation

With n = 0, the condition n > 0 is False. The next condition, n == True, evaluates False because in Python True behaves as the integer 1, and 0 is not equal to 1. Since neither the if nor the elif condition is satisfied, control passes to the else block, which executes print("***"), outputting three stars.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!