-1

I am writing program for hangman game. this is not matter. when I pass a parameter to the life function, it printing the specific elif block. but also None is print in end of the output.

the program is:

def life(n):
    if n==6:
        print("|\n|\n|\n|\n|\n")
    elif n==5:
        print("________\n|    |\n|\n|\n|\n|\n|")
    elif n==4:
        print("________\n|    |\n|    O\n|\n|\n|\n|")
    elif n==3:
        print("________\n|    |\n|    O\n|    |\n|    |\n|    \n|")
    elif n==2:
        print("________\n|    |\n|    O\n|   /|\ \n|    |\n|    \n|")
    elif n==1:
        print("________\n|    |\n|    O\n|   /|\ \n|    |\n| __/_\__\n| |||||||")
    elif n==0:
        print("________\n|    |\n|    O\n|   /|\ \n|    |\n|   / \ \n|")

print(life(5))

I attached my output. why the None is printing? please anyone explain me detail. output: Output

I want to know only the reason of the output.

radha
  • 1

1 Answers1

-2
> def life(n):
>     if n==6:
>         return "|\n|\n|\n|\n|\n"
>     elif n==5:
>         return "________\n|    |\n|\n|\n|\n|\n|"
>     elif n==4:
>         return "________\n|    |\n|    O\n|\n|\n|\n|"
>     elif n==3:
>         return "________\n|    |\n|    O\n|    |\n|    |\n|    \n|"
>     elif n==2:
>         return "________\n|    |\n|    O\n|   /|\ \n|    |\n|    \n|"
>     elif n==1:
>         return "________\n|    |\n|    O\n|   /|\ \n|    |\n| __/_\__\n| |||||||"
>     elif n==0:
>         return "________\n|    |\n|    O\n|   /|\ \n|    |\n|   / \ \n|"
> 
> print(life(5))

or

def life(n):
    if n==6:
        print("|\n|\n|\n|\n|\n")
    elif n==5:
        print("________\n|    |\n|\n|\n|\n|\n|")
    elif n==4:
        print("________\n|    |\n|    O\n|\n|\n|\n|")
    elif n==3:
        print("________\n|    |\n|    O\n|    |\n|    |\n|    \n|")
    elif n==2:
        print("________\n|    |\n|    O\n|   /|\ \n|    |\n|    \n|")
    elif n==1:
        print("________\n|    |\n|    O\n|   /|\ \n|    |\n| __/_\__\n| |||||||")
    elif n==0:
        print("________\n|    |\n|    O\n|   /|\ \n|    |\n|   / \ \n|")

life(5)
ANDRVV
  • 7
  • 5
  • It would be nice if you added an explanation and if you would format the code of the first example. – Matthias May 28 '23 at 17:05
  • in your code print(life(5)), print() is trying to print a result that the function returns. In this case in the function you are not returning any value but you are printing it. Returning no output it prints nothing which would be None, I hope this explanation is useful to you, and if it works accept my answer with ✔️ – ANDRVV May 28 '23 at 21:48