while循环练习:
生活随笔
收集整理的這篇文章主要介紹了
while循环练习:
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
輸入姑娘的年齡后,進行以下判斷:
如果姑娘大于25歲小于45歲,打印“阿姨好”
如果姑娘大于45歲,打印“奶奶好”
age=input('請輸入你的年齡:') age=int(age) if age >= 45:print('奶奶好') elif age>=25:print('阿姨好') elif age >= 18:print('心動表白') else:print('不接受未成年')預習while循環,打印1-100之間的奇數和
count=0 sum=0 while count<100:count+=1if count%2== 1:sum += count print(sum)預習while循環,猜年齡游戲升級版,有以下三點要求:
允許用戶最多嘗試3次
每嘗試3次后,如果還沒猜對,就問用戶是否還想繼續玩,如果回答Y或y, 就繼續讓其猜3次,以此往復,如果回答N或n,就退出程序
如果猜對了,就直接退出
age=18 count=0 while count<3:guess_age = input('請輸入你的年齡:').strip()guess_age = int(guess_age)if guess_age>age:print('猜大了')elif guess_age<age:print('猜小了')else:print('猜對了')breakcount+=1if count==3:choice = input('繼續請輸入:Y/y或退出請輸入:N/n:').strip()if choice == 'y' or choice == 'Y':count = 0elif choice == 'N' or choice == 'n':break轉載于:https://www.cnblogs.com/jinhongquan/p/11506976.html
總結
以上是生活随笔為你收集整理的while循环练习:的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Spring学习(三)Spring AO
- 下一篇: 基本运算符与if while详解: