import random def playGame(): humChoice = input("Rock, Paper, or Scissors?: ") humChoice = (humChoice.lower()) print("you have chosen " + humChoice) compOptions = ["rock", "paper", "scissors"] x = random.randint(0,2) compChoice = compOptions[x] print("the computer has chosen " + compChoice) winDict = {"rock":"scissors", "scissors":"paper", "paper":"rock"} winner = -1 if (humChoice == compChoice): print("It's a tie!") elif (winDict.get(humChoice) == compChoice): print("{} beats {}. You win!".format(humChoice, compChoice)) winner = 0 elif (humChoice not in winDict): print("That is not rock, paper, or scissors. What game do you think this is?") else: print("{} beats {}. You lose!".format(compChoice, humChoice)) winner = 1 return winner def main(): print("welcome to rock paper scissors!") playAgain = True scoreboard = [0,0] while playAgain: winner = int(playGame()) if (winner >= 0): scoreboard[winner] += 1 print("Current Scores: ") print("You: " + str(scoreboard[0])) print("Computer: " + str(scoreboard[1])) again = input("Would you like to play again? (type 'no' to exit): ") if again == ("no" or "No"): print("Thanks for playing!") playAgain = False if __name__ =='__main__': main()
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