# Python 3 # Nikhil Jain # This is a version of rock, paper, scissors # where the computer adjusts what it plays # depending on what you play import random # initialize equal probabilities for rock, paper, scissors probs = ['rock'] * 1 + ['paper'] * 1 + ['scissors'] * 1 def game_loop(): while True: # computer chooses computer_choice = random.choice(probs) # get user choice user_choice = input("\nEnter rock, paper, or scissors: ") if user_choice in ["rock", "paper", "scissors"]: print("The computer played " + computer_choice + ", and you played " + user_choice) if user_choice == computer_choice: print("It's a tie!") # Determine outcome of round, and adjust computer probabilities # by weighting the winning move more heavily elif user_choice == "rock" and computer_choice == "paper": print("You lose.") probs.append("paper") elif user_choice == "rock" and computer_choice == "scissors": print("You win!") probs.append("paper") elif user_choice == "scissors" and computer_choice == "rock": print("You lose.") probs.append("rock") elif user_choice == "scissors" and computer_choice == "paper": print("You win!") probs.append("rock") elif user_choice == "paper" and computer_choice == "scissors": print("You lose.") probs.append("scissors") elif user_choice == "paper" and computer_choice == "rock": print("You win!") probs.append("scissors") else: print("Try again.")
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