python笔记-循环-创新互联

条件判断与缩进,注意冒号
加次数限制
#猜数字
lucky_num = 19
input_num = -1

创新互联建站提供网站建设、做网站、网页设计,成都品牌网站建设一元广告等致力于企业网站建设与公司网站制作,十载的网站开发和建站经验,助力企业信息化建设,成功案例突破上1000+,是您实现网站建设的好选择.

#次数限制
count = 0
#while lucky_num!=input_num and count < 3:
while count < 3:
input_num = int(input("please input your lucky_num:"))
if input_num < lucky_num:
print("please input big num")
elif input_num > lucky_num:
print("please input little num")
else:
print("great")
break
count += 1
print(count)
else:
print("too many counts!!!!")
注意缩进,python是对缩进敏感的语言
注释:ctrl+/

for循环
#次数限制
for i in range(3):
input_num = int(input("please input your lucky_num:"))
if input_num < lucky_num:
print("please input big num")
elif input_num > lucky_num:
print("please input little num")
else:
print("great")
break
else:
print("too many counts!!!!")


网页题目:python笔记-循环-创新互联
URL分享:http://hbruida.cn/article/iddgd.html