python 循环while和for in简单实例
程序员文章站
2023-12-18 08:24:04
python 循环while和for in简单实例
#!/uer/bin/env python
# _*_ coding: utf-8 _*_
luckn...
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简单实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。