I am a beginner in python and was trying to write a code for a game : Snake, Water and Gun. Can anyone help me to check why the function is not returning any value?
The logic seems accurate.
import random
def game_logic(ct,ut):
if(ct==ut): #ct is computer turn and ut is user turn
return None #print("Game tied:")
elif(ct=="Snake" and ut=="Gun"):
return True #print("User wins!")
elif(ct=="Snake" and ut=="Water"):
return False #print("Computer wins!")
elif(ct=="Water" and ut=="Gun"):
return False #print("Computer wins!")
elif(ct=="Water" and ut=="Snake"):
return True #print("User wins!")
elif(ct=="Gun" and ut=="Snake"):
return False #print("Computer wins!")
elif(ct=="Gun" and ut=="Water"):
return True #print("Computer wins!")
cturn=["Snake","Gun","Water"]
uturn= input("select snake(S),gun(G) or water(W):")
S="Snake"
G="Gun"
W="Water"
if(uturn=="S"):
print("The user selected: Snake")
elif(uturn=="W"):
print("The user selected: Water")
elif(uturn=="G"):
print("The user selected: Gun")
else:
print("wrong input")
ct=random.choice(cturn)
print("The computer selected: ",ct)
Z=game_logic(ct,uturn)
if (Z):
print("Hurray! You won the game")
else:
print("Bad Luck!")