Saturday, 15 March 2014

Python While loop keeps repeating -


I am trying to use this program and I think the program does not repeat the program again Too many programs:

  # menu menu = int (input ("what do you want? \ N \ 1. a compliment \ n \ 2. how to use an offense \ n A program to use. \ N \ 3. a proverb \ n ")) y = true while y == true: if menu == 1: #compliment print (" you look good today ") elif Nu == 2: #inint print ("you smell") alif menu == 3: #Proverb print ("A bird in the hand is worth two in the bush!") And: Y == wrong print ("invalid option") Break what happens when i type the option for example 2 repeats the program you smell you smell you do odor you smell you smell you smell the infinite bar We do.   

your while the loop never ends in your last 'other' Under you have a break, but you believe that your variable menu will actually be modified, you should not looping on the response, but overall instead:

 < Code> y = true while y == true: menu = int (input ("what do you want? \ N \ 1. a compliment \ n \ 2. an insult \ n \ 3. a saying \ n")) if Menu == 1: #compliment print ("You are good today ) "Elif menu == 2: #intult print (" You smell ") Alif menu == 3: #proverb Print (" A bird in the hand is worth two in the bush! "): Print (" invalid " Option ") y = wrong  

The above will run as long as no invalid option is entered and the loop will break. Since y your original code can never be broken, your y == incorrect is a comparison operation, not an assignment operation, however, it still does not hit anytime Because, because you are not asking for additional input within your loop, so it will be forever TRUE .


No comments:

Post a Comment