#Steal or Deal #By Alex O'Rourke # import random PTotal = 0 AITotal = 0 MAX_GAMES = 10 count = 0 pchoice = "" aichoice = "" print("Welcome to Steal or Deal!") print("==========================") print("\n1. Always steal") print("2. Always deal") print("3. Random") #aichoice = input("Which strategy for the computer [1,2,3]?") #while aichoice not in (1, 2, 3): # aichoice = input("Which strategy for the computer [1,2,3]?") while aichoice != '1' or aichoice != '2' or aichoice != '3': aichoice = input("Which strategy for the computer [1,2,3]?") print("\nPlease enter either 1, 2, or 3.") while count < MAX_GAMES and pchoice != 'q': count = count + 1 print("Please enter either 's', 'd' or 'q'") pchoice = input("\nSteal, Deal or Quit [s|d|q]?") AIChoice = random.randint(1,2) if AIChoice == 1: AIChoice = "Steal" elif AIChoice == 2: AIChoice = "Deal" if pchoice == "s" and AIChoice == "Steal": print('Jackpot: 100 ') print('Current turn: ',count) print('You chose: Steal') print('Comp chose: ', AIChoice) print('Too greedy! You get nothing!') print('>> Your score: ', PTotal, '-- Comp score: ', AITotal,'<<') elif pchoice == "d" and AIChoice == "Deal": print('Jackpot: 100 ') print('Current turn: ',count) print('You chose: Deal') print('Comp chose: ', AIChoice) print('Draw! Split pot - 50 each!') PTotal = PTotal + 50 AITotal = AITotal + 50 print('>> Your score: ', PTotal, '-- Comp score: ', AITotal,'<<') elif pchoice == "s" and AIChoice == "Deal": print('Jackpot: 100 ') print('Current turn: ',count) print('You chose: Steal') print('Comp chose: ', AIChoice) print('You win! You gain 100') PTotal = PTotal + 100 print('>> Your score: ', PTotal, '-- Comp score: ', AITotal,'<<') elif pchoice == "d" and AIChoice == "Steal": print('Jackpot: 100 ') print('Current turn: ',count) print('You chose: Deal') print('Comp chose: ', AIChoice) print('You lose! You get nothing!') AITotal = AITotal + 100 print('>> Your score: ', PTotal, '-- Comp score: ', AITotal,'<<') elif pchoice == "q": print ('You chose to quit')
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