import random import time b1=int(10) b2=int(10) b3=int(10) print(f"{b1} {b2} {b3}") while b1 > 0 or b2 > 0 or b3 > 0: bag = int(input("Enter the num of the bag(1-3): ")) if bag>=1 and bag<=3: ball = int(input("Enter the num of the balls(1-5): ")) if ball>=1 and ball<=5 : if bag==1 and b1>=ball: b1=b1-ball elif bag==2 and b2>=ball: b2=b2-ball elif bag==3 and b3>=ball: b3=b3-ball else: print("wrong no. of balls") continue else: print("wrong no. of balls") continue else: print("wrong no. of bag") continue print(f"{b1} {b2} {b3}") if b1==0 and b2==0 and b3==0: print("User wins!!") break while(1): cbag = random.randint(1,3) if cbag>=1 and cbag<=3: cball = random.randint(1,5) if cball>=1 and cball<=5 : if cbag==1 and b1>=cball: print("-----------------------------------------------------") print("Computer's turn") b1=b1-cball print(f"Computer took {cball} from {cbag}") print(f"{b1} {b2} {b3}") print("-----------------------------------------------------") print("Your turn") print(f"{b1} {b2} {b3}") break elif cbag==2 and b2>=cball: print("-----------------------------------------------------") print("Computer's turn") b2=b2-cball print(f"Computer took {cball} from {cbag}") print(f"{b1} {b2} {b3}") print("-----------------------------------------------------") print("Your turn") print(f"{b1} {b2} {b3}") break elif cbag==3 and b3>=cball: print("-----------------------------------------------------") print("Computer's turn") b3=b3-cball print(f"Computer took {cball} from {cbag}") print(f"{b1} {b2} {b3}") print("-----------------------------------------------------") print("Your turn") print(f"{b1} {b2} {b3}") break else: continue else: continue else: continue if b1==0 and b2==0 and b3==0: print("Computer wins!!") break time.sleep(30)
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