Home > Article > Backend Development > python loop while and for in examples
Python simple examples of while loop and 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!")
The above article is a simple example of python loop while and for in This is all the content that the editor has shared with you. I hope it can give you a reference, and I also hope that everyone will subscribe to the PHP Chinese website.
For more articles related to python loop while and for in examples, please pay attention to the PHP Chinese website!