Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Rock, Paper, Scissors by Don Gruszka
- import random
- choices = ["rock", "paper", "scissors"]
- wins = 0
- ties = 0
- losses = 0
- while True:
- # Gets input from player 1
- print("\n")
- print("Please choose 1 for rock, 2 for paper, 3 for scissors or q to quit.")
- player_guess = input("Please input your choice: ")
- ai_guess = random.randint(0, 2)
- player2 = choices[ai_guess] #naming this variable player2 is confusing because of
- # the inconsistency of the variable above it being called ai_guess. Maybe name it ai_choice or something
- # do this in your while loop i.e. while player_guess != 'q' instead of while True:
- if player_guess == 'q':
- break
- # Tries to see if numeric value was input correctly
- try:
- play = int(player_guess) - 1
- except:
- print("Please enter a numeric value for your choice!")
- # Checks for valid int to play game.
- if play > 2:
- print("There is no lizard or Spock in this version!!!")
- break
- player1 = choices[play]
- # Prints choices and determines winner
- print("You chose: {}, The computer chose: {}.".format(player1, player2))
- # Can you think of a way you could use a data structure to represent the relationship between rock, paper and scissors?
- # And use that data structure to make this code much simpler?
- if (player1 == "rock" and player2 == "scissors") or (player1 == "scissors" and player2 == "paper") or ( player1 == "paper" and player2 == "rock"):
- print("You win!!!")
- wins += 1
- elif player1 == player2:
- print("You tied!")
- ties += 1
- else:
- print("You lose!")
- losses += 1
- # Prints you win/loss record.
- print("Wins = {}, Ties = {}, Losses = {}".format(wins, ties, losses))
- print("\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement