简体   繁体   中英

Python returning 'None'

Everything else in my code is working, but every time it asks to add a new item to the list, python also returns 'None' I'm trying to get rid of this, any help would be appreciated.

This is my code:

#Welcome
name = input("What is your name? ")
print("Welcome %s to your shopping list" %name)

#Adding to the list
shoppingList = []
while True:
    new_item = input(print("Please enter an item of your shopping list and type END when you have entered all of your items: "))
    if new_item == "END": break
    shoppingList.append(new_item)
length = len(shoppingList)
print("Your shopping list is", length, "item(s) long.")
shoppingList.sort
print("This is your list: ", shoppingList)

#Prompting the user to change list if necessary
change = input(print("Is there anything you wish to change?"))
if 'No' in change: print("Great.")
else:
    delete = input(print("Which item would you like to replace?"))
    shoppingList.remove(delete)
replace = input(print("What would you like to replace it with?"))
shoppingList.append(replace)
print("This is your new list: ", shoppingList)

You're calling print() inside of input() , and print() returns None . Simply pass the string to input() :

input("Is there anything you wish to change?")

Also, shoppingList.sort won't do anything. You need to call it properly: shoppingList.sort() .

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