• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Help with python

tigris649

Member
I have just started programming with python and I am practicing with the if and while statement. In this program I have caused yes to become False, which should end the loop in my program right? But it doesn't the program just keeps looping and doesn't end, why is this?

Thanks in advance
 
The while loop is infinite because you have it tied to the boolean "True" instead of "yes". If you replace "True" with "yes" it works fine:

yes = True
while yes:
sport = (raw_input('What is your favorite sport : '))
if sport == 'quit':
yes = False
elif sport == 'hockey':
print 'Your favorite sport is', sport
 
Back
Top