import random prize=random.randint(1,3); print(prize) inp=int(input("Pick door 1, 2, or 3\n")) doors=[i for i in range(1,4)] #is there a faster way to check the input validity? while(inp!=1 and inp!=2 and inp!=3): inp=int(input("That is not a valid input. Pick door 1, 2, or 3\n")) doors=[i for i in range(1,4)] doors.remove(inp) openDoor=doors[random.randint(0,1)] print("Just to help you out, I'll tell you that there is no prize in door # "+str(openDoor)) keepswitch=input("Enter keep or switch") #inp=int(input("Pick door 1, 2, or 3\n")) #print(keepswitch) while(keepswitch!="keep" and keepswitch!="switch"): keepswitch=input("That is not a valid input. Enter \"keep\" or \"switch\"") if(keepswitch=="switch"): doors.remove(openDoor) inp=doors[0] if(inp==prize): print("Congratulations, you win!") else: print("Sorry, you didn't get the prize")
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question