import random
player = input("Player, make your move: ").lower()
choice_list = ["rock", "fire", "scissors", "sponge", "paper", "air", "water"]
computer = random.choice(choice_list)
beats_dict = {"rock":["scissors", "sponge", "fire"],
"fire":["scissors", "sponge", "paper"],
"scissors":["sponge", "paper", "air"],
"sponge":["paper", "air", "water"],
"paper":["air", "water", "rock"],
"air":["water", "rock", "fire"],
"water":["rock", "fire", "scissors"],}
print(f"Computer plays {computer}" )
if computer in beats_dict[player]:
print("player wins!")
elif player in beats_dict[computer]:
print("computer wins!")
else:
print("It's a tie!")
What do you think about this construction? Is it good or it can be improved? I mean is it a dictionary with lists good and short for this type? Or I can reformat it to be better and shorter?
Aucun commentaire:
Enregistrer un commentaire