Reputation:
I've checked around and can't seem to find what exactly I am looking for. I've tried to do this a few different ways, but the best way I can come up with is using an empty dictionary and adding some key pairings. I'm unsure what exactly random.choice(list(weapons.values()))
is pulling from the dictionary. Is it getting the key or the value?
import random
weapons = {}
weapons[3] = "Rock"
weapons[2] = "Scissors"
weapons[1] = "Paper"
player_1 = input("Choose your weapon. ")
player_2 = random.choice(list(weapons.values()))
if player_1 == "Rock" and player_2 == "Paper":
print(player_2,"Computer wins!")
elif player_2 == "Rock" and player_1 == "Paper":
print(player_2,"Player 1 wins!")
elif player_1 > player_2:
print(player_2,"Player 1 wins!")
elif player_2 > player_1:
print(player_2,"Computer wins!")
elif player_1 == player_2:
print(player_2,"Tie!")
else:
print("Please enter rock, paper, or scissors. ")
Upvotes: 0
Views: 38
Reputation: 95
.values always return values of dictionary keys. Please check this https://www.programiz.com/python-programming/methods/dictionary/values
random.choice is selecting random values at a time from the list of dictionary values .
Upvotes: 1