首页 > 代码库 > Python学习笔记三:while循环

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循环