Help with python

tigris649

Member
Feb 21, 2008
84
0
0
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
 

Dimmu

Senior member
Jun 24, 2005
890
0
0
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
 

Crusty

Lifer
Sep 30, 2001
12,684
2
81
Because your loop is an infinite loop. You have "while True:", which is never ever false.