Its a beginner program that involves playing (rock, paper, scissors, lizard, spock) Is my code correct? There aren't any syntax errors on IDLE but I cant seem to get it to work. Any ideas. I'm new to Python. Thanks very much
def pnumber_to_name(player_number):
# fill in your code below
if player_number == 0:
return rock
elif player_number == 1:
return Spock
elif player_number == 2:
return paper
elif player_number == 3:
return lizard
else:
return scissors
# convert number to a name using if/elif/else
# don't forget to return the result!
def cnumber_to_name(comp_number):
# fill in your code below
if comp_number == 0:
return rock
elif comp_number == 1:
return Spock
elif comp_number == 2:
return paper
elif comp_number == 3:
return lizard
else:
return scissors
#def name_to_number(name):
# fill in your code below
# if rock:
# name = 0
# elif Spock:
# name = 1
# elif paper:
# name = 2
# return name
# convert name to number using if/elif/else
# don't forget to return the result!
def rpsls(name):
pnumber_to_name(player_number)
cnumber_to_name(comp_number)
player_number = random.randrange(0,5)
comp_number = random.randrange(0,5)
name = (player_number - comp_number)%5
if name == 1 or 2:
print ('Player chooses', pnumber_to_name(player_number))
print ('Computer chooses', cnumber_to_name(comp_number))
print ('Player wins')
elif name == 3 or 4:
print ('Player chooses', number_to_name(number,(player_number)))
print ('Computer chooses', number_to_name(number,(comp_number)))
print ('Comp wins')
elif name == 0:
print ('Player chooses', number_to_name(number,(player_number)))
print ('Computer chooses', number_to_name(number,(comp_number)))
print ('Player and computer tie')
rock
,Spock
etc defined? What errors do you get exactly? – Mischa Arefiev Oct 19 '12 at 12:19dict
s instead. – Rik Poggi Oct 19 '12 at 12:46