Advertisement
Guest User

Untitled

a guest
Aug 24th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. # Rock, Paper, Scissors by Don Gruszka
  2.  
  3. import random
  4.  
  5. choices = ["rock", "paper", "scissors"]
  6.  
  7. wins = 0
  8. ties = 0
  9. losses = 0
  10.  
  11. while True:
  12. # Gets input from player 1
  13. print("\n")
  14. print("Please choose 1 for rock, 2 for paper, 3 for scissors or q to quit.")
  15. player_guess = input("Please input your choice: ")
  16. ai_guess = random.randint(0, 2)
  17. player2 = choices[ai_guess] #naming this variable player2 is confusing because of
  18. # the inconsistency of the variable above it being called ai_guess. Maybe name it ai_choice or something
  19.  
  20. # do this in your while loop i.e. while player_guess != 'q' instead of while True:
  21. if player_guess == 'q':
  22. break
  23.  
  24. # Tries to see if numeric value was input correctly
  25. try:
  26. play = int(player_guess) - 1
  27. except:
  28. print("Please enter a numeric value for your choice!")
  29.  
  30. # Checks for valid int to play game.
  31. if play > 2:
  32. print("There is no lizard or Spock in this version!!!")
  33. break
  34. player1 = choices[play]
  35.  
  36. # Prints choices and determines winner
  37. print("You chose: {}, The computer chose: {}.".format(player1, player2))
  38.  
  39. # Can you think of a way you could use a data structure to represent the relationship between rock, paper and scissors?
  40. # And use that data structure to make this code much simpler?
  41. if (player1 == "rock" and player2 == "scissors") or (player1 == "scissors" and player2 == "paper") or ( player1 == "paper" and player2 == "rock"):
  42. print("You win!!!")
  43. wins += 1
  44. elif player1 == player2:
  45. print("You tied!")
  46. ties += 1
  47. else:
  48. print("You lose!")
  49. losses += 1
  50.  
  51. # Prints you win/loss record.
  52. print("Wins = {}, Ties = {}, Losses = {}".format(wins, ties, losses))
  53. print("\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement