python循环while和forin简单实例#!/uer/bin/envpython#_*_coding:utf-8_*_lucknumber=5b=0whileb<3:print('gusscount:
python 循环while和for in简单实例
#!/uer/bin/env python
# _*_ coding: utf-8 _*_
lucknumber = 5
b = 0
while b <3:
print('guss count:',b)
a = int(input('you guse number'))
if a > lucknumber:
print ('youaerbiger')
elif a == lucknumber:
print ('youare righet')
break #跳出这个层级的循环
else :
print ('you aer smaller')
b +=1 #在while循环中,+=1 是必须循环体
else:
print ("Too many retrys!")
#________________________________________________
for i in range(3):
a = int(input('you guse number')) #注意用int()表示输出的是 数字类型
if a > lucknumber:
print ('youaerbiger')
elif a == lucknumber:
print ('youare righet')
break
else :
print ('you aer smaller')
else:
print ("Too many retrys!")
以上这篇python 循环while和for in简单实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。
python for while循环