我的工作有问题代码。这些只是我程序的一个例子。在for循环和if语句中有一个for循环。我的目标是打印下面的输出
The dogs that i like are
bulldogs
poodle
beagle
pug
The dogs that i don't like are
boxer
rottweiler
bullterrier
sheltie
我试过这个代码,但好像有什么不对劲。你知道吗
sample = [['The dogs that i like are'], ["The dogs that i don't like are"]]
sample_2 = ['bulldogs', 'poodle', 'beagle','pug', 'boxer', 'rottweiler','bullterrier','sheltie']
i = 'pug'
for s in sample:
print (sample)
for s2 in sample_2:
print (sample_2)
if sample_2 == i:
print ("\n");
假设你已经离开了电脑
方法:
1:列两张单子,一张上面有你喜欢的狗的名字,另一张上面有你不喜欢的狗的名字。你知道吗
2:遍历列表以打印其名称。你知道吗
输出:
相关问题 更多 >
编程相关推荐