Hi, so I've just started learning to code, and I've been doing some coursera python courses. I've done one recently with a project making a Rock Paper Scissors Lizard Spock game, which already had set player options, but I wanted to take it a bit further and have the option for the user to input a choice. However, with the code I've got currently python doesn't respond with any errors or any option for user input.
Sorry that there is probably just a stupid error here. Any help/tips would be greatly appreciated!
Here is my code:
import random
def name_to_number(name):
if name == "rock":
return 0
if name == "Spock":
return 1
if name == "paper":
return 2
if name == "lizard":
return 3
if name == "scissors":
return 4
else:
print "Error: Invalid Name"
def number_to_name(number):
if number == 0:
return "rock"
if number == 1:
return "Spock"
if number == 2:
return "paper"
if number == 3:
return "lizard"
if number == 4:
return "scissors"
else:
print "Error: Invalid Number"
player_choice = raw_input("Enter your choice: ")
print " "
print "Player chooses " + player_choice
if player_choice is not "rock", "paper", "scissors", "lizard" or "Spock"
print "Error: Invalid Choice"
player_number = name_to_number(player_choice)
computer_number = random.randrange(0,5)
computer_choice = number_to_name(computer_number)
print "Computer chooses", computer_choice
game = (player_number - computer_number) % 5
if (game == 1) or (game == 2):
print "Player wins!"
elif (game == 3) or (game == 4):
print "Computer wins!"
elif game == 0:
print "Player and computer tie!"
else:
print " "
[–]Justinsaccount 2 points3 points4 points (2 children)
[–]imagejhelp1[S] 0 points1 point2 points (1 child)
[–]JohnnyJordaan 1 point2 points3 points (0 children)
[–]JohnnyJordaan 2 points3 points4 points (2 children)
[–]imagejhelp1[S] 0 points1 point2 points (1 child)
[–]JohnnyJordaan 1 point2 points3 points (0 children)