Skip to content

Instantly share code, notes, and snippets.

@calthoff
Last active January 15, 2020 19:29
Show Gist options
  • Select an option

  • Save calthoff/acb9bfd4acdb6a35f3aae59f7c50b5e7 to your computer and use it in GitHub Desktop.

Select an option

Save calthoff/acb9bfd4acdb6a35f3aae59f7c50b5e7 to your computer and use it in GitHub Desktop.
def RockPaperScissors():
import random
global options, cpu, user, x, y #There is no reason to make these global variables when they are inside a function
print("Welcome to rock, paper, scissors!\nType q if you want to quit the game.\nor!")
x = 0
y = 0
while True:
options = ["rock","paper","scissors"]
cpu = random.choice(options)
user = input("Pick one of the following: rock, paper or scissors? ")
user = user.lower() #good
if user == "q" or user == "quit": # How does the user know to type either of these things?
print("Good bye!")
break
elif (user in options) == False: # You don't need ( )
print("Input ERROR! You are a silly User, a very silly User!")
print("System will now restart!")
RockPaperScissors() # Don't call your function here this is bad practice.
# You are using recursion for no reason
# Use the keyword continue instead
# try to think of what the relationship is between rock, paper, and scissors. Is there a data structure
# you can use that takes advantage of this relationship and reduces the amount of code you need?
elif user == "rock" and cpu == "scissors":
print("User chooses {} and Computer chooses {}.".format(user,cpu))
print("User wins, well done User!")
x += 1
elif user == "paper" and cpu == "rock":
print("User chooses {} and Computer chooses {}.".format(user,cpu))
print("User wins, well done User!")
x += 1
elif user == "scissors" and cpu == "paper":
print("User chooses {} and Computer chooses {}.".format(user,cpu))
print("User wins, well done User!")
x += 1
elif user == cpu:
print("User chooses {} and Computer chooses {}.".format(user,cpu))
print("Draw! No points are awarded.")
else:
print("User chooses {} and Computer chooses {}.".format(user,cpu))
print("Computer wins, well done Computer!")
y += 1
print("The score is: User {} to Computer {}.".format(x,y))
RockPaperScissors()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment