日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python编写成绩及格不及格_python小练习:读入一个考试得分,判断这个分数是哪个等级,并输出,考虑异常场景...

發布時間:2023/12/19 python 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python编写成绩及格不及格_python小练习:读入一个考试得分,判断这个分数是哪个等级,并输出,考虑异常场景... 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

讀入一個考試得分,判斷這個分數是哪個等級,并輸出。

等級:》=90 優 ,>=80且小于90 良,》=70 且小于80,中,》=60且<70及格

《60 不及格

覆蓋場景:

考慮字符類型(str,float)

數字范圍(0-100)以外的

小數98.99等

代碼:

#encoding=utf-8

while True:

try:

score = raw_input("input the score,'exit' to stop: >>:")

#print type(score)

#print isinstance(score,str)

if "exit" in score:

break

else:

score = float(score)

print "score:",score

if score >= 90 and score <=100:

print u"優"

elif score>=80 and score <90:

print u"良"

elif score >=70 and score <80:

print u"中"

elif score >= 60 and score <70:

print u"及格"

elif score >=0 and score <60:

print u"不及格"

else:

print u"請重新輸入!"

except Exception,e:

print e

print u"請重新輸入!"

continue

結果:

D:\>python test.py

input the score,'exit' to stop: >>:90

score: 90.0

input the score,'exit' to stop: >>:100

score: 100.0

input the score,'exit' to stop: >>:89

score: 89.0

input the score,'exit' to stop: >>:78

score: 78.0

input the score,'exit' to stop: >>:67

score: 67.0

及格

input the score,'exit' to stop: >>:56

score: 56.0

不及格

input the score,'exit' to stop: >>:1

score: 1.0

不及格

input the score,'exit' to stop: >>:0

score: 0.0

不及格

input the score,'exit' to stop: >>:-2

score: -2.0

請重新輸入!

input the score,'exit' to stop: >>:9.3

score: 9.3

不及格

input the score,'exit' to stop: >>:8.88

score: 8.88

不及格

input the score,'exit' to stop: >>:90.89

score: 90.89

input the score,'exit' to stop: >>:101

score: 101.0

請重新輸入!

input the score,'exit' to stop: >>:200

score: 200.0

請重新輸入!

input the score,'exit' to stop: >>:stop

could not convert string to float: stop

請重新輸入!

input the score,'exit' to stop: >>:sdlfj

could not convert string to float: sdlfj

請重新輸入!

input the score,'exit' to stop: >>:*&%$

could not convert string to float: *&%$

請重新輸入!

input the score,'exit' to stop: >>:exit

總結

以上是生活随笔為你收集整理的python编写成绩及格不及格_python小练习:读入一个考试得分,判断这个分数是哪个等级,并输出,考虑异常场景...的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。