#Author: Machi Dima
#Assignment: Rock, Paper, Scissors
#Date: 05/07/2020
#Import random Library
import random
#create and fill array variable choices
choices = ["rock", "paper", "scissors"]
#set background color to purple
stage.set_background_color("Purple")
#create object that display on screen 2 pictures on opposite sides
computer = codesters.Sprite("computer", -150,0)
user = codesters.Sprite("profilepicture", 150,0)
#request input from user and store it in variable user_choice
user_choice = user.ask("Rock, paper or scissors?")
#open while loop to validate user input
while user_choice not in choices:
user_choice = user.ask("Please Re-enter Rock, papaer or scissors")
#display what the user entered
user.load_image(user_choice)
#for loop where the random library is used to randomly
#select a choice for the comp_choice
for i in range(random.randint(10,20)):
comp_choice= random.choice(choices)
computer.load_image(comp_choice)
#display text who is the winner
winner = codesters.Text("", 0, 150)
#if condition that compares user_choice == comp_choice if equal
#set winner text to Tie
if user_choice == comp_choice:
winner.set_text("Tie")
#else if condition that checks if user inputed rock
#and then continous to compare with the random comp_choice
#to decide who won
elif user_choice == "rock":
if comp_choice == "paper":
winner.set_text("Computer Wins")
else:
winner.set_text("User Wins")
#else if condition that checks if user inputed paper
#and then continous to compare with the random comp_choice
#to decide who won
elif user_choice == "paper":
if comp_choice == "scissors":
winner.set_text("Computer Wins")
else:
winner.set_text("User Wins")
#else if condition that checks if user inputed scissors
#and then continous to compare with the random comp_choice
#to decide who won
elif user_choice == "scissors":
if comp_choice == "rock":
winner.set_text("Computer Wins")
else:
winner.set_text("User Wins")
-
Run Code
-
-
Stop Running Code
-
Show Chart
-
Show Console
-
Codesters How To (opens in a new tab)