Last active
December 30, 2019 20:51
-
-
Save calthoff/44547e3476c5fb5169b6de3445a8462c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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