python loop while and for in examples

高洛峰
Release: 2017-02-25 11:43:08
Original
1439 people have browsed it

Python simple examples of while loop and for in

#!/uer/bin/env python
# _*_ coding: utf-8 _*_

lucknumber = 5
b = 0

while b <3:
  print(&#39;guss count:&#39;,b)
  a = int(input(&#39;you guse number&#39;))
  if a > lucknumber:
    print (&#39;youaerbiger&#39;)
  elif a == lucknumber:
    print (&#39;youare righet&#39;)
    break                 #跳出这个层级的循环
  else :
    print (&#39;you aer smaller&#39;)
  b +=1                  #在while循环中,+=1 是必须循环体
else:
  print ("Too many retrys!")

#________________________________________________

for i in range(3):
  a = int(input(&#39;you guse number&#39;))   #注意用int()表示输出的是 数字类型
  if a > lucknumber:
    print (&#39;youaerbiger&#39;)
  elif a == lucknumber:
    print (&#39;youare righet&#39;)
    break
  else :
    print (&#39;you aer smaller&#39;)
else:
  print ("Too many retrys!")
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!