Jan-24-2019, 10:28 PM
Trying to learn more pythonic ways of doing things.
How'd I do? Any suggestions welcome, please.
How'd I do? Any suggestions welcome, please.
import random combinations = {"Paper": {"Rock": "Win", "Paper": "Draw", "Scissors": "Lose"}, "Rock": {"Paper": "Lose", "Rock": "Draw", "Scissors": "Win"}, "Scissors": {"Paper": "Win", "Scissors": "Draw", "Rock": "Lose"} } scoring = {"Win": 1, "Draw": 0, "Lose": -1} user_choice = "" score = 0 while user_choice.title() != "Quit": print("\nPaper, Rock, Scissors, or Quit") user_choice = input("Please enter your choice: ").title() computer_choice = list(combinations)[random.randint(0, 2)] try: result = combinations[user_choice][computer_choice] score += scoring[result] print("Your choice %s: Computer choice %s: You %s: Your Score %d" % (user_choice, computer_choice, result, score)) except: if user_choice == "Quit": print("Final score: %d" % score) else: print("Invalid Entry") input()