【发布时间】:2021-07-04 13:57:29
【问题描述】:
我是 python 新手,在查看课程时,我想到了一些我找不到解决方案的东西:
proteins = ["venison", "tuna", "chicken"]
veggies = ["kale", "spinach", "tomatoes"]
for i in proteins:
for j in veggies:
if j == "spinach":
print("Spinach?!? Feed it to the dog")
print(i,j)
print(type(j))
结果:
venison kale
Spinach?!? Feed it to the dog
venison spinach
venison tomatoes
tuna kale
Spinach?!? Feed it to the dog
tuna spinach
tuna tomatoes
chicken kale
Spinach?!? Feed it to the dog
chicken spinach
chicken tomatoes
我的意图是,而不是打印“鹿肉菠菜...”和肉和菠菜,实际上,是用句子(“菠菜?!?喂狗”)而不是打印“菜单” .
我的想法是,
每当j==spinach我们
print("Spinach?!? Feed it to the dog")
在这里我们转到下一个索引之前
print(i,j).
我该怎么做?
希望我的问题有意义! 谢谢,
【问题讨论】:
-
您是否正确复制了缩进?我没有得到与您显示的相同的输出。
-
如果
print(i, j)缩进另一个级别,我会得到该输出。 -
你能描述一下你想要的输出吗?
-
请edit您的帖子并添加您的预期输出
标签: python