【发布时间】:2022-12-18 19:48:15
【问题描述】:
*我是编程的新手,所以如果我的代码有任何可以改进的地方,请告诉我。
我想让输出每次都在新行中打印出列表,我以某种方式做到了这一点 :),但它也多次打印 [None],有人可以向我解释为什么会这样吗以及我如何能够摆脱它,无论是通过使用“\r”还是其他东西。
这是我的代码:
# All Toppings
toppings = ["cheese", "olives", "pepperoni", "mushrooms", "sausage", "pineapple", "anchovies"]
# The Prices
prices = ["$2", "$6", "$1", "$3", "$2", "$7", "$2"]
prices.sort()
# Number of Toppings
num_pizzas = len(toppings)
# Combing Pizza Toppings and Prices
pizza_and_prices = list(map(list,zip(prices,toppings)))
#After the Guy Bought the Last Anchovies Slice
pizza_and_prices.pop()
pizza_and_prices.append(["$2.5", "peppers"])
#ACTUAL MENU
print("***TOOZIE'S PIZZARIA***")
print("We sell " + str(num_pizzas) + " different kinds of Pizza!")
print(list(map(print, pizza_and_prices)))
这是输出:
***TOOZIE'S PIZZARIA***
We sell 7 different kinds of Pizza!
['$1', 'cheese']
['$2', 'olives']
['$2', 'pepperoni']
['$2', 'mushrooms']
['$3', 'sausage']
['$6', 'pineapple']
['$2.5', 'peppers']
[None, None, None, None, None, None, None]
【问题讨论】:
标签: python-3.x