简体   繁体   中英

When I run this, I get a "None" to respond to instead of my question

When I run the code, I want the user to respond to the "What do you want?", line. Instead the input line shows up next to "None". Also, PyCharm says something about 'expecting two blank lines, but got 0' in my def shop_interface line. I include the rest of the function, in case I need to put something lower.

I put it in the function block, but I think I'm missing something, I tried putting the item_wanted input into the function, but I think that makes things worse.

yes = "yes"
print("Welcome to Python's Shop! What can I do for you?")
item_wanted = input(print("What do you want? Food? Bed?: "))
def shop_interface():
    gold = 200
    if item_wanted == "food":
        print("I have some apples to buy! 20G Each!")
    input("Want them?:")
    if yes:
        gold = gold - 20
        print("You have " + str(gold) + "G left")
    elif item_wanted == "bed":
        print("I have a room for about 15G...want it?")
    elif item_wanted == "weapon":
        print(" There's an old sword in the back, I'll give it to you for 100G.")
    else:
        print("Don't have that, we have food and bed though!")

I want the input line to be next to "What do you Want? Food? Bed?"line, instead of none displaying. Thanks for any help!

Tom Karzes is right; You should change input(print("...")) to input("...") . The way you're currently doing it uses the output of print, which is None . Your code currently is equivalent to input(None) , which is why you've been getting that weird None . The correct code would be input("What do you want? Food? Bed?: ") .

You have this

item_wanted = input(print("What do you want? Food? Bed?: "))

But that is not going to work as print does not return anything. It just prints to the sys.stdout (it can also print to a stream) whatever you pass to it.

You should in fact do this

item_wanted = input("What do you want? Food? Bed?: ")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM