Created
March 7, 2017 19:00
-
-
Save calthoff/87543262b8becd79cb07ccffeb1223e3 to your computer and use it in GitHub Desktop.
This file contains 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
import random | |
def rock_paper_scissors(): | |
options = ["rock", "paper", "scissors"] | |
wins = {"rock": "scissors", "scissors": "paper", "paper": "rock"} | |
player_wins = 0 | |
comp_wins = 0 | |
player_pick = None | |
name = input("What is your name?") | |
while player_pick != "q": | |
player_pick = input("type rock paper or scissors or q to quit:") | |
if player_pick not in options: | |
print("invalid choice") | |
continue | |
print("The score is: {} {}. Computer {}".format(name, player_wins, comp_wins)) | |
print("{} picked {}".format(name, player_pick)) | |
comp_pick = options[random.randint(0, 2)] | |
print("The computer picked {}".format(comp_pick)) | |
if wins[comp_pick] == player_pick: | |
print("The computer won. {} beats {}".format(comp_pick, player_pick)) | |
comp_wins += 1 | |
elif wins[player_pick] == comp_pick: | |
print("The player won. {} beats {}".format(player_pick, comp_pick)) | |
player_wins +=1 | |
else: | |
print("You both picked {}. It's a tie".format(player_pick)) | |
rock_paper_scissors() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment