Python Forum
Need help !!! Loop is not moving
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help !!! Loop is not moving
#1
print("Help! My computer doesn't work!")
done = False
while not done:
    print("Does the computer make any sounds (fans, etc.) ")
    choice = (input("or show any lights? (y/n):"))
if choice == "n":
    choice = input("Is it plugged in? (y/n):")
if choice == 'n':
    print("Plug it in.")
else:
    choice = input("Is the switch in the \"on\" position? (y/n):")
if choice == 'n':
    print("Turn it on.")
else:
    choice = input("Does the computer have a fuse? (y/n):")
if choice == 'n':
    choice = input("Is the outlet OK? (y/n):")
if choice == 'n':
    print("Check the outlet's circuit ")
    print("breaker or fuse. Move to a")
    print("new outlet, if necessary. ")
else:
    print("Please consult a service technician.")
    done = True
------------------------------------------------------------
Output ---- Not moving to next if loop , it keep on asking the same
Output:
Help! My computer doesn't work! Does the computer make any sounds (fans, etc.) or show any lights? (y/n):n Does the computer make any sounds (fans, etc.) or show any lights? (y/n):y Does the computer make any sounds (fans, etc.) or show any lights? (y/n):
------ > It suppose to ask "Is it plugged in? (y/n):" if i enter n in the choice , isn't ?
Reply
#2
Please use proper code tags (see the BBCode link in my signature below) and post in the correct forum. I have corrected your post for now. If the indentation shown in the corrected post above is correct, then the problem is that everything from if choice == 'n': is outside of the while loop. You need to indent all the code you want to be part of the loop in one level.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3

Reply
#4
Here's your entire loop.
Quote:
done = False
while not done:
    print("Does the computer make any sounds (fans, etc.) ")
    choice = (input("or show any lights? (y/n):"))

At no point do you change the variable done, so the loop continues again. Forever.
Reply
#5
Thanks All , i fixed it.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020