Issue with function not returning value

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!")

Your variable names are very hard to read. You should use words.

In any cas’, can you describe the problem in more detail? How isn’t it working? What steps can we take to reproduce the error?

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

Because the user input is a single character but your function doesn’t have any case for that. You don’t actually turn the input into the word.

1 Like