Python Forum
Need help !!! Loop is not moving - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Need help !!! Loop is not moving (/thread-12216.html)



Need help !!! Loop is not moving - aankrose - Aug-14-2018

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 ?


RE: Need help !!! Loop is not moving - ichabod801 - Aug-14-2018

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.


RE: Need help !!! Loop is not moving - aankrose - Aug-14-2018





RE: Need help !!! Loop is not moving - nilamo - Aug-14-2018

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.


RE: Need help !!! Loop is not moving - aankrose - Aug-14-2018

Thanks All , i fixed it.