r/pythonhelp • • May 31 '22

Why does it print 'none'?

Why does it print 'none' when I start my code?

import random options1 = 1 options2 = [ ["Move"], ["Pillage", "Move", "or Shop"], ["Loot", "Move", "or shop"] ] money = 0 move = 0 loot = [ "Drugs", "Jewels", "Money" ]

def moving(): random.shuffle(options2) if options2[0] == ["Loot", "Move", "or shop"]: ifmav = input(print("What would you like to do? \nWrite "LOOT" to loot nearby chests,\n"MOVE" to move,\nand "SHOP" to check our shop"))

if options1 == 1: options = input(print("What would you like to do?" " Write "MOVE" to move. ")) if options == "MOVE": move += 1 print("You chose to move!") moving()

def find_loot(): random.shuffle(loot) print(loot[0])

2 Upvotes

1 comment sorted by

1

u/kaleidist May 31 '22 edited May 31 '22

So this is your code when I format it:

import random
options1 = 1
options2 = [["Move"], ["Pillage", "Move", "or Shop"], ["Loot", "Move", "or shop"]]
money = 0
move = 0
loot = ["Drugs", "Jewels", "Money"]

def moving():
    random.shuffle(options2)
    if options2[0] == ["Loot", "Move", "or shop"]:
        ifmav = input(print("What would you like to do? \nWrite \"LOOT\" to loot nearby chests,\n\"MOVE\" to move,\nand \"SHOP\" to check our shop"))

    if options1 == 1:
        options = input(print("What would you like to do? Write \"MOVE\" to move. "))
    if options == "MOVE":
        move += 1
        print("You chose to move!")
moving()

def find_loot():
    random.shuffle(loot)
    print(loot[0])

To answer your question technically, the reason it prints "None" is because input() takes a positional argument which it prints. So when you put print(...) inside of input(), that calls the print() method twice. It prints the positional arguments for print() but also prints whatever the print method itself returns. The print method itself returns None. So you end up printing both the string you have inside print(...) and None. The solution you want is to leave out the print(), such as:

input("What would you like to do? Write \"MOVE\" to move. ")

That will print just that string and then take user input.

There are some other issues with your code, but hopefully this gets you on your way.