Python Program won't restart -



Python Program won't restart -

this question exact duplicate of:

restart python programme [duplicate]

i trying restart programme in python, but, reason, code getting caught in while playagain loop. says "that not valid answer. please come in 'yes' or 'no'." when come in yes, no, or of other inputs acceptable. why won't work?

while true: playagain = input("would play again?") while playagain != "y" or playagain != "y" or playagain != "yes" or playagain != "yes" or playagain != "yes" or playagain != "n" or playagain != "n" or playagain != "no" or playagain != "no" or playagain != "no": print("that not valid answer. please come in 'yes' or 'no'.") playagain = input("would play again?") if playagain == "y" or playagain == "y" or playagain == "yes" or playagain == "yes" or playagain == "yes": break else: print("thank playing madlibs!")

you can utilize lower() function , in operator clean code.

you alter code:

playagain = input("would play again?").lower() while playagain not in ['y', 'yes', 'n', 'no']: print("that not valid answer. please come in 'yes' or 'no'.") playagain = input("would play again?").lower()

so whole code be:

while true: playagain = input("would play again?").lower() while playagain not in ['y', 'yes', 'n', 'no']: print("that not valid answer. please come in 'yes' or 'no'.") playagain = input("would play again?").lower() if playagain in ['n', 'no']: print("thank playing madlibs!") break

python

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -