Sign InCoursewareNuggetsTutorials CoursesCodePad

Rock Paper Scissors

Write a Rock Paper Scissors game in Python. You and the computer each need to make a choice of rock, paper or scissors. These two choices are compared and the winner is declared. Remember the three rules: rock crushes scissors, scissors cut paper, paper covers rock.

# Write a program to play Rock Paper Scissors game with the computer. import random player = input("Enter your choice (rock/paper/scissors): ") player = player.lower() choices = ["rock", "paper", "scissors"] while player not in choices: print(player); player = input("That choice is not valid. Enter your choice (rock/paper/scissors): ") player = player.lower() computer = random.choice(choices) print("You chose " + player + " and the computer chose " + computer + ".") # Write your code here to print out game result.
© CS Wonders·About·Gallery·Fun Facts·Cheatsheet