Python Forum
Roshambo with only 1 if switch
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Roshambo with only 1 if switch
#4
maybe a better choice of data structure, using f-strings, random.choice

import random
game = {"Paper":[("Rock", "Win"),
                ("Paper", "Draw"),
                ("Scissors", "Lose")],
        "Rock":[("Scissors", "Win"),
                ("Rock", "Draw"),
                ("Paper", "Lose")],
        "Scissors":[("Paper", "Win"),
                    ("Scissors", "Draw"),
                    ("Rock", "Lose")]}
scoring = {"Win": 1, "Draw": 0, "Lose": -1}
score = 0
while True:
    print("\nPaper, Rock, Scissors, or Quit")
    user_choice = input("Please enter your choice: ").title()
    if user_choice == "Quit":
        break
    try:
        computer_choice, result = random.choice(game[user_choice])
    except KeyError:
         print("Invalid Entry")  
    else:
        score += scoring[result]
        print(f"Your choice {user_choice} | Computer choice {computer_choice} | You {result} | Your Score {score}")
input(f"Final score: {score}")
Further steps - maybe using collections.namedtuple
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Messages In This Thread
Roshambo with only 1 if switch - by Clunk_Head - Jan-24-2019, 10:28 PM
RE: Roshambo with only 1 if switch - by ichabod801 - Jan-24-2019, 11:55 PM
RE: Roshambo with only 1 if switch - by Clunk_Head - Jan-25-2019, 12:02 AM
RE: Roshambo with only 1 if switch - by buran - Jan-25-2019, 08:20 AM
RE: Roshambo with only 1 if switch - by Clunk_Head - Jan-26-2019, 06:16 PM
RE: Roshambo with only 1 if switch - by perfringo - Jan-25-2019, 09:30 AM
RE: Roshambo with only 1 if switch - by Clunk_Head - Jan-27-2019, 03:19 AM
RE: Roshambo with only 1 if switch - by buran - Jan-25-2019, 09:37 AM
RE: Roshambo with only 1 if switch - by perfringo - Jan-25-2019, 11:48 AM
RE: Roshambo with only 1 if switch - by buran - Jan-26-2019, 06:56 PM
RE: Roshambo with only 1 if switch - by perfringo - Jan-27-2019, 09:02 AM
RE: Roshambo with only 1 if switch - by Clunk_Head - Jan-27-2019, 10:19 PM
RE: Roshambo with only 1 if switch - by perfringo - Jan-28-2019, 08:59 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  switch to python3 Skaperen 0 2,160 Jul-03-2018, 12:55 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020