2014-11-16 7 views
0

Все остальное в моем коде работает, но каждый раз, когда он просит добавить новый элемент в список, python также возвращает «None». Я пытаюсь избавиться от этого, любая помощь будет оценили.Python return '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) 

ответ

5

Вы звоните print() внутри input() и print() возвращается None. Просто передать строку в input():

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

Кроме того, shoppingList.sort не будет ничего делать. Вы должны назвать это правильно: shoppingList.sort().

+0

Спасибо, много помогли! –

Смежные вопросы