【发布时间】:2022-12-01 20:57:10
【问题描述】:
current code:
list = [1,2,3,4,5]
for i in list:
Dev.step(2)
if i == 2 or 1 or 0:
Dev.turnLeft()
Dev.step(Dev.x-Item[i].x)
Dev.step(Dev.x-15)
Dev.turnRight()
else:
Dev.turnRight()
Dev.step(Item[i].x-Dev.x)
Dev.step(15-Dev.x)
Dev.turnLeft()
How do I create an if statement for the Dev / Character do something for a specific list element or filter the list elements. Example I want, if the number of 'i' is equal to 2 or 1 or 0 the Dev will turnLeft. So the output of the list is seperated with the other numbers.
Example: [2,1,0] and [4,5]
Create an if statement for a specific list elements / numbers.
【问题讨论】:
-
use of
inoperator likeif i in [2,1,0]:? -
Does this answer your question? Why does "a == x or y or z" always evaluate to True? How can I compare "a" to all of those?
标签: python