I'm attempting to program a stone, paper, scissors test system game in Python. It works generally, however incidentally, when I enter my decision of rock, paper, or scissors for the information doled out to variable "guess," nothing is returned. Much obliged to you! Here is the program:
def main():
print('This game is rock, paper, scissors')
number=userguess()
num=computernumber()
result(number, num)
#computernumber function assigns number to rock, paper, scissors
def computernumber():
num=random.randint(1,4)
if num==1:
print('Computer picks rock')
elif num==2:
print('Computer picks paper')
elif num==3:
print('Computer picks scissors')
return num
#userguess assigns rock, paper, scissors to a number
def userguess():
guess=input("Choose, 'rock','paper',or 'scissors:") #<- this input prompt
if valid(guess):
if guess== 'rock':
number=1
elif guess== 'paper':
number=2
elif guess== 'scissors':
number=3
return number
else:
print('Please choose a valid response')
return userguess()
def valid(guess):
if guess=='rock' or guess=='paper' or guess=='scissors':
result= True
else:
result= False
return result
def restart():
again=input('Play again? (y/n)')
if again=='y':
main()
elif again=='n':
print('Goodbye')
else:
print('please enter y or n')
restart()
#function to display result
def result(num,number):
if number==num:
print('Tie')
restart()
elif number==1 and num==2:
print('you won!')
restart()
elif number==1 and num==3:
print ('you lost!')
restart()
elif number==2 and num==1:
print('you lost!')
restart()
elif number==2 and num==3:
print('you won!')
restart()
elif number==3 and num==1:
print('you won!')
restart()
elif number==3 and num==2:
print('you lost!')
restart()
main()