Skip to main content
elearn.ellak.gr
  • Home
  • More
You are currently using guest access
Log in
Home
  1. Open Courses in English
  2. python_ellak_may_2017
  3. Week 2 - May 14
  4. Assignment 2.2
Assignment

Assignment 2.2

Assignment 2.2

Completion requirements
Opened: Saturday, 13 May 2017, 12:00 AM

Write a program that plays rock, paper, scissorsRock Paper Scissors

  • Create a program that randomly prints 0, 1, or 2.
  • Expand the program so it randomly prints rock, paper, or scissors using if statements. 
  • Add to the program so it first asks the user their choice. (It will be easier if you have them enter 1, 2, or 3.)
  • Add conditional statement to figure out who wins.

The following is a sample code to start with. It is not the best code for solving the game but it is very analytic and understandable.

import random user = int(input("Select Rock:1, Paper:2 or Scissors:3 : ")) if user == 1: print("User selected Rock") elif user == 2: print("User selected Paper") else: print("Usel selected Scissors") comp = random.randint(1,3) if comp == 1: print("Computer selected Rock") elif comp == 2: print("Computer selected Paper") else: print("Computer selected Scissors") if comp == user: print ("It is a tie") elif user == 1 and comp == 3: print("User Wins") # add the other cases #elif #else:

◄ Assignment 2.1 - Answer
Assignment 2.2 - Answer ►
You are currently using guest access (Log in)
Data retention summary
Get the mobile app
Powered by Moodle