[英]Python returning 'None'
我代碼中的其他所有內容均正常運行,但是每次要求將新項目添加到列表中時,python也會返回“ None”,我試圖擺脫這一點,我們將不勝感激。
這是我的代碼:
#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)
您在input()
print()
內部調用print()
,而print()
返回None
。 只需將字符串傳遞給input()
:
input("Is there anything you wish to change?")
另外, shoppingList.sort
不會執行任何操作。 您需要正確地調用它: shoppingList.sort()
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.