我有两个变量
例:
compt = 9
first = 3
second = 2
然后我想根据compnt长度循环,然后根据变量first和second更改状态on或off
我想要的输出:
On
On
On
Off
Off
On
On
On
Off
我目前的代码是:
x,y=0,0
for i in range(0,compt):
if x != first:
print("On")
x+=1
elif x == first and y != second:
print("Off")
但是上面代码的输出是
On
On
On
Off
Off
On
On
On
On
有人能帮我解决我的问题吗,谢谢
输出:
另一个与
itertools
有关的变体:输出:
相关问题 更多 >
编程相关推荐