# import plus class of library
import random
#Create an array of choices for loop iteration and set background.
choices = ("rock", "paper", "scissors")
stage.set_background("hauntedhouseinterior")
#Can Set color as well with stage.set_background_color("")
#Create an object with subclass along with 3 argument parameters
#first argument is sprite name then the place coordinates x and y
computer = codesters.Sprite("ghost8",-150,0)
user = codesters.Sprite("ghost3",150,-15)
#Create an object to obtain input from the end user
user_choice = user.ask("What's your choice? rock, paper, or scissors")
#Create an Error Checking with the use of a while loop
while user_choice not in choices:
user_choice = user.ask("Please enter rock, paper, or scissors")
#Create an image for data type of a string input from user
user.load_image(user_choice)
#Create logic for computer's random guess, Import random library with a for loop
for i in range(random.randint(13,31)):
#Create random guess from choice array
computer_choice = random.choice(choices)
#Create image for data type for sting input from computer
computer.load_image(computer_choice)
#Create an object that outputs to the screen with text attribute with 3 arguments
#First being empty string then the x and y coordinates
winner = codesters.Text("",0,150)
#Create if statement with else if to place logic and determine winner
if user_choice == computer_choice:
winner.set_text("Tie!")
#Creating logic to determine the winner of rock, paper, scissors.
elif user_choice == "rock":
#Nested if condition
if computer_choice == "paper":
winner.set_text("Computer Wins")
else:
winner.set_text("Player Wins! Happy Halloween")
#Create another choice option
elif user_choice == "scissors":
#Nested if condition
if computer_choice == "rock":
winner.set_text("Computer Wins!")
else:
winner.set_text("Player Wins! Happy Halloween!")
#Create a last else statemnt with the same flow as previous 2 to end control flow statemnt
else:
if computer_choice == "scissors":
winner.set_text("Computer Wins!")
else:
winner.set_text("Player Wins! Happy Halloween!")
-
Run Code
-
-
Stop Running Code
-
Show Chart
-
Show Console
-
Codesters How To (opens in a new tab)