您有两个列表
fruits = ["strawberries", "apples", "bananas", "pomegranates", "blueberries", "dragon fruits", "papayas", "pears", "oranges", "mango", "tomatoes", "peaches", "melons", "watermelons"]
所以...
favoritefruits = [fruits[0], fruits[2], fruits[3], fruits[7], fruits[8], fruits[13]]
要迭代,您不需要使用i
.只需使用
for fruit in fruits:
if fruit in favoritefruits:
print("I'm gonna buy some " + fruit + " because they are one of my favorite fruits.")
else:
print("I'm not going to buy " + fruit + ", I don't like them.")
输出:
I'm gonna buy some strawberries because they are one of my favorite fruits.
I'm not going to buy apples, I don't like them.
I'm gonna buy some bananas because they are one of my favorite fruits.
I'm gonna buy some pomegranates because they are one of my favorite fruits.
I'm not going to buy blueberries, I don't like them.
I'm not going to buy dragon fruits, I don't like them.
I'm not going to buy papayas, I don't like them.
I'm gonna buy some pears because they are one of my favorite fruits.
I'm gonna buy some oranges because they are one of my favorite fruits.
I'm not going to buy mango, I don't like them.
I'm not going to buy tomatoes, I don't like them.
I'm not going to buy peaches, I don't like them.
I'm not going to buy melons, I don't like them.
I'm gonna buy some watermelons because they are one of my favorite fruits.