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


uturn= input("select snake(S),gun(G) or water(W):")





    print("The user selected: Snake")


     print("The user selected: Water")


            print("The user selected: Gun")


    print("wrong input")


print("The computer selected: ",ct)


if (Z):

   print("Hurray! You won the game")


  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