其他
Psychopy | 第2期:从Stroop看条件与循环
list = ['red', 'blue']
for word in list:
for color in list:
if word == color:
condition = 'same'
else:
condition = 'diff'
print(condition, word, color)
if <布尔表达式>:
<代码段 | pass>
a = 1
b = 2
if a < b:
print('a<b')
a = 2
b = 1
if a < b:
print('a<b')
a = 2
b = 1
if a < b:
print('a<b')
else:
print('a>=b')
a = 0
if a <= 1 and a >= 5:
print('right')
else:
print('wrong')
a = 0
if 1 < a < 5:
print('wrong')
else:
print('right')
a = 2
b = 1
if a < b:
print('a<b')
elif a == b:
print('a==b')
elif a > b:
print('a>b')
a = 2
b = 1
if a < b:
print('a<b')
elif a == b:
print('a==b')
else:
print('a>b')
for <变量> in <序列>:
<代码段 | pass>
for i in ['a','b','c','d','e']:
print(i)
while <布尔表达式>:
<代码段 | pass>
a = 0
while a<2:
a+=1
print(a)
a = 0
while a<2:
a+=1
print(a)
a = 0
while a<2:
a+=1
print(a)
while True:
<代码段 | pass>
a = 0
while True:
a+=1
print(a)
if a == 2:
break
for i in ['a','b','c','d','e']:
if i == 'c':
break
print(i)
a = 0
while True:
a+=1
if a == 2:
continue
print(a)
if a == 4:
break
for i in ['a','b','c','d','e']:
if i == 'c':
continue
print(i)
list = ['red', 'blue']
for word in list:
for color in list:
if word == color:
condition = 'same'
else:
condition = 'diff'
print(condition, word, color)