Skip to content

Instantly share code, notes, and snippets.

@calthoff
Last active December 30, 2019 20:51
Show Gist options
  • Select an option

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

Select an option

Save calthoff/44547e3476c5fb5169b6de3445a8462c to your computer and use it in GitHub Desktop.
# Play the fun game of Rock-Paper-Scissors:
import random
def rock_paper_scissors():
options = ["rock", "paper", "scissors"]
auto_selection = random.choice(options)
user_selection = input ("\nSelect one of the following: \nROCK! PAPER! SCISSORS! ")
# You don't need ( ) around True
while (True):
if (user_selection.lower() in options) == False: # You don't need ( )
print("This is not a valid selection. Try again \nTo quit, type \"quit\" anytime.")
rock_paper_scissors() # this line of code is not necessary because it is inside a while-loop. It happens anyway
break # remove
if (options.index(auto_selection) - options.index(user_selection.lower()) == 1) or (options.index(auto_selection) - options.index(user_selection.lower()) == -2):
print ("You loose. Play again ") # You don't need ( )
print ("I selected " + auto_selection)
rock_paper_scissors() # this line of code is not necessary because it is inside a while-loop. It happens anyway
break # remove
# put a space here
elif options.index(auto_selection) - options.index(user_selection.lower()) == 0:
print ("You're even. Play again" )
print ("I selected " + auto_selection)
rock_paper_scissors() # this line of code is not necessary because it is inside a while-loop. It happens anyway
break # remove
else:
print ("You win!")
print ("I selected " + auto_selection)
break
rock_paper_scissors()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment