編寫乙個輸入分數,輸出分數等級的程式,具體為:
score grade
90~100 a
70~89 b
60~69 c
0~59 d
others invalid score
請新增必要的輸入輸出語句,盡量讓程式友好。
score = eval(input("enter the score: "))
if 0 <= score <= 100:
if 90 <= score <= 100:
grade = "a"
elif score >= 70:
grade = "b"
elif score >= 60:
grade = "c"
elif score >= 0:
grade = "d"
print("the grade of {} is {}.".format(score, grade))
else:
print("invalid score")
編寫程式,從鍵盤輸入乙個二元一次方程ax^2+bx+c=0的三個引數a、b、c(均為整數),求此方程的實根。如果方程有實根,則輸出實根(保留一位小數),如果沒有實根則輸出沒有實根的資訊。
[輸入樣例1]
1,0,-1
[輸出樣例1]
x1 = 1.0, x2 = -1.0
[輸入樣例2]
1,2,1
[輸出樣例2]
x = -1.0
[輸入樣例3]
2,2,3
[輸出樣例3]
no real solution
from math import sqrt
a, b, c = eval(input())
t = b*b-4*a*c
if t > 0:
x1 = (-b+sqrt(t))/(2*a)
x2 = (-b-sqrt(t))/(2*a)
print('x1 = , x2 = '.format(x1, x2))
elif t == 0:
x = -b/(2*a)
print('x = '.format(x))
else:
print("no real solution")
MOOC程式設計程式設計作業6 2
現有一整數集 允許有重複元素 初始為空。我們定義如下操作 add x 把x加入集合 del x 把集合中所有與x相等的元素刪除 ask x 對集合中元素x的情況詢問 對每種操作,我們要求進行如下輸出。add 輸出操作後集合中x的個數 del 輸出操作前集合中x的個數 ask 先輸出0或1表示x是否曾...
python之條件判斷
if 語句在執行時,會先對條件表示式進行求值判斷 如果為true,則執行if 後的語句 如果為false 則不執行 a 10b 20if a print 123 塊 print 123 塊 print 123 塊 123123 123if 條件表示式 塊else 塊 只有乙個廁所,男的可以進入,女的...
python之條件判斷
一 python之if語句 計算機之所以能做很多自動化的任務,因為它可以 自己做條件判斷。比如,輸入使用者年齡,根據年齡列印不同的內容,在 python程式中,可以用if語句實現 age 20 if age 20 print your age is age print adult print end...