Python学习笔记三:while循环

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python学习笔记三:while循环相关的知识,希望对你有一定的参考价值。

简单的while循环:

 1 age_konishi = 23 
 2 
 3 count = 0  #定义一个计数器
 4 while count < 3:  #循环小于三次执行下列代码
 5     guess_age = int(input("Age: "))
 6     if guess_age == age_konishi:
 7         print("Yoshi! Sugoi!")
 8         break  #猜对时强制跳出
 9     elif guess_age > age_konishi:
10         print("You‘re so bad!")
11     else:
12         print("Honey, you‘re so sweetie!")
13     count += 1
14 else:  #循环大于三次执行下列代码
15     print("Idiot! I give you too many times!")

 

以上是关于Python学习笔记三:while循环的主要内容,如果未能解决你的问题,请参考以下文章