0

print(a * 5)?

I think this quiz question is just designed to throw people off, but wanted to check here as not completely sure. a = 5 while a < 5: a += 5 print(a * 5) Output: 25 #(a * 5) evaluates to (5 * 5) to 25, but what's with the while loop? "While a is less than five the same a equals a plus 5?" 5 is not less than 5, so shouldn't the output be an error (or undefined)? Or does the upper portion of the code to be ignored (and if so, how am I to know that)? Thanks for any help.

12th Apr 2019, 9:48 PM
tristach605
tristach605 - avatar
1 Answer
+ 1
The while loop is ignored because its condition never holds true. No undefined behavior at all. This is the same as doing the following. a = 41 if a == 42: print("Hello") print("World!") The if block is ignored because its condition is False, so only the last message is printed.
12th Apr 2019, 10:36 PM
Diego
Diego - avatar