Okay, so i saw a program that my friend made for Rock Paper Scissors and he challenged me to replicate it, i think i got most of it, but raw_input stopped working, also I’m trying this out on the first lesson i just deleted everything and wrote my own code, so if that has anything to do with it please let me know. Thanks!
<edit: i recently changed the code because of a useful reply by @ionatan and it works perfectly Thank You for your contribution! >
Here’s the code:
from time import sleep
from random import randint
The following code prints the instructions:
print “Welcome to Rock, Paper, Scissors!”
print “”“To play the game you must choose either rock, paper, or scissors. The computer will then randomly generate either rock, paper, or scissors. If you beat the computer you win! “””
print “”
sleep(1)
Now we get computer choice
def computer_choice():
chosen = randint(1,3)
return randint(1,3)
Next we get the user’s choice and save it as user_choice
user_choice = raw_input("Rock, Paper, or Scissors? ")
def user_choice():
user_choice = raw_input("Which will you choose? ")
return user_choice
# Now we reassign the computer’s number as a new string to make things easier later on
if chosen == 1:
computer_choice = “Rock”
elif chosen == 2:
computer_choice = “Paper”
elif chosen == 3:
computer_choice = “Scissors”
#We print the computer’s choice
sleep(1)
print “The computer chose:”
print computer_choice
sleep(1)
Now we compare the computer choice with the user choice to determine the result
if user_choice == “Rock” and computer_choice == “Rock”:
print “It was a draw, restart and try again”
elif user_choice == “Rock” and computer_choice == “Paper”:
print “Sorry, but you have lost”
elif user_choice == “Rock” and computer_choice == “Scissors”:
print “YOU WON!”
elif user_choice == “Paper” and computer_choice == “Rock”:
print “YOU WON!”
elif user_choice == “Paper” and computer_choice == “Paper”:
print “It was a draw, restart and try again”
elif user_choice == “Paper” and computer_choice == “Scissors”:
print “Sorry, but you have lost”
elif user_choice == “Scissors” and computer_choice == “Rock”:
print “Sorry, but you have lost”
elif user_choice == “Scissors” and computer_choice == “Scissors”:
print “It was a draw, restart and try again”
elif user_choice == “Scissors” and computer-choice == “Paper”:
print “YOU WON!”
else:
print “ERROR 591: INVALID INPUT”
print “”
and we print a closing statement
sleep (1)
print “”
print “Thank you for playing Rock, Paper, Scissors. Goodbye!”