mercredi 26 février 2020

Python Rock Paper Scisssors Assigning String to random variable

I am writing a python rock, paper, scissors, lizard, spock program for a class The computers pick is a random integer and the user is prompted to enter a number. It then displays the results and tells you who won. The program is running properly except for the print statement. I'm trying to get the program to show the computer pick and the user pick as the word instead of the number and I'm not sure of the best way to go about this. Currently, it prints the number as the answer. Any suggestions?

*computer = random.randint (0, 4)
user = eval(input("Enter a number between 0 and 4: O for scissors, 1 for paper, 2 for rock, 3 for lizard, 4 for Spock"))* 

*if computer == user:
    print("You tied, you both picked", user)
elif computer == 0 and user == 1:
    print("The computer picked ", computer, " you picked ", user, ". Computer wins!")*

The computer picked 4 you picked 3 . You win!

I'd like it to print as

The computer picked scissors you picked rock. You win!




Aucun commentaire:

Enregistrer un commentaire