我正在学习Python第3卷的速成课程,我正在学习第8-12章,这是关于函数的。以下是我目前的代码:
def sandwich_builder(bread,*items):
print(f"What type of bread do you want?")
bread=input("Type of Bread:")
print(f"Making your sandwich on {bread} bread with the following items:")
for item in items:
print(f"-{item}")
sandwich_builder('turkey','bacon','avocado','cheddar','mayonnaise','tomato','lettuce')
但是,我的输出如下所示:
Making your sandwich on sourdough bread with the following items:
-bacon
-avocado
-cheddar
-mayonnaise
-tomato
-lettuce
我的函数为什么不输出列表中的第一项?谢谢。你知道吗
删除函数“bread”,然后将列表中的第一项设置为该参数。你知道吗
我期望函数打印列表中的第一项,但它没有
只需从函数中删除一个不必要的参数。否则你就得把一个也不传给面包。你知道吗
下面的代码行设置了
bread='turkey'
和items = ['bacon', 'avocado', 'cheddar','mayonnaise','tomato','lettuce']
。你知道吗然后使用
bread=input("Type of Bread:")
重写bread
的值。你知道吗若要修复它,请从函数中删除
bread
作为参数。你知道吗相关问题 更多 >
编程相关推荐