031004 for 循环 (1)

# EXAMPLE_NUM01

for i in range(10):
print("loop ", i)

# i 是一个 临时变量 从 0 开始循环
# range 相当于 变量的一组数据

# EXAMPLE_NUM02

age_of_oldboy = 56
for i in range(3):
guess_age = int(input("guess age:")) # input 输入默认为 字符串
if guess_age == age_of_oldboy:
print("yes, you got it.")
break
elif guess_age > age_of_oldboy:
print("think smaller...")
else:
print("think bigger!")
else: # else 相当于 代码正常走完了,如果不正常,则 break 了,就破坏循环,不执行了
print("you have tried too many times...damn the hell")

猜你喜欢

转载自www.cnblogs.com/azxsdcv/p/12458010.html
今日推荐