0
Too Young Too Drive - Python
Iām having some trouble with this Code Coach. I think something might be wrong with the else statement. What do I fix it? i = 0 while i<3: rider_age = int(input()) i+=1 if rider_age <17: print("Too young!") break else: print("Get ready!")
4 Answers
+ 3
If you want "Get ready!" to print only once (which actually makes more sense, my mistake for assuming otherwise), you can readjust the indentation of the 'else' to extend from 'while' instead of 'if':
i = 0
while i<3:
rider_age = int(input())
i+=1
if rider_age <17:
print("Too young!")
break
else:
print("Get ready!")
This way, the if statement still belongs inside the while loop. Here the else clause will only be executed if the loop exits normally (without break).
+ 2
Indentation is important in python. The statements that you wish to run within the while loop must be indented by 1 level for it to be part of the loop. Same goes for the if and else statements. Try this:
i = 0
while i<3:
rider_age = int(input())
i+=1
if rider_age <17:
print("Too young!")
break
else:
print("Get ready!")
0
The code prints āGet Ready!ā three times. How do I change the code to make it print the phrase one time only?
0
Thank you so much!