I am coding a rock paper scissor lizard spock game, and I want to associate a number with the player character. I was wondering if it is possible to choose a random variable from a list of variables similar to:
import random
class Characters():
def __init__(self, player, weight, winphrase, losephrase):
self.weight = weight
self.player = player
self.winphrase = winphrase
self.losephrase = losephrase
choice1 = Characters(1, "Rock", "crushes","crushes")
choice2 = Characters(2, "Paper", "covers","disproves")
choice3 = Characters(3, "Lizard", "eats","poisons")
choice4 = Characters(4, "Spock", "vaporizes", "smashes")
choice5 = Characters(5, "Scissor", "cuts","decpitates")
choices = [choice1, choice2, choice3, choice4, choice5]
npc_choice = random.choice(choices)
print(npc_choice)
print("1) Rock")
print("2) Paper")
print("3) Scissor")
print("4) Lizard")
print("5) Spock")
print("Quit")
print("-----------------")
character = input("Pick a Character ")
Currently the code spits an error when I print npc_choice. How do I print the random choice data properly?
Aucun commentaire:
Enregistrer un commentaire