Python返回'无'

时间:2014-11-16 21:17:30

标签: python list python-3.x nonetype

我的代码中的其他所有内容都正常工作,但每次要求在列表中添加新项目时,python也会返回'无。我试图摆脱这个,任何帮助都会受到赞赏。

这是我的代码:

#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)

1 个答案:

答案 0 :(得分:5)

您在print()内拨打input()print()返回None。只需将字符串传递给input()

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

此外,shoppingList.sort不会做任何事情。您需要正确调用它:shoppingList.sort()