在這個簡單的 python 程序中,我們要找到一個學生的年級。這是一個學生級的 python 程序。
要理解這個例子,您應該了解以下 Python 編程主題:
- Python 語法
- Python 運算符
- Python 決策語句
如何用 python 找到一個學生的成績?
相加一個科目的分數,顯示一個學生的成績,是一個常見的 python 程序。這是一個初級程序,因為我們需要輸入學生每個科目的分數。我們使用 python 方法和基礎知識,通過取科目的分數總和,再除以科目總數,來計算科目分數的平均值。
從分數的平均值來看,我們用 python 中的if
條件和elif
來計算分數,分數取決於分數的平均值。
例如,讓我們舉一個學生的例子,他們的分數是 10 分中的 8,7,9,6,8。分數的平均值是 7.6,然後我們計算分數。a 或 B 或 C 或 D 或 F 取決於數字 9、8、7、6 和 5。所以這裡,等級是 c。
算法
第一步:使用輸入法分別接受用戶對每個科目的評分。然後使用 python 編程語言中的int()
將該字符串轉換為整數。
第二步:將平均值計算為分數之和,用總數除以被試人數。
步驟 3: 使用if
條件,使用平均值檢查等級。如果平均值高於 90,則打印 A 。
STEP 4: 使用 python 語言的elif
語句打印 B、C、D 的成績,具體取決於 80、70、60 這樣的平均分。
步驟 5: 如果數值小於 50,使用else
條件打印等級 F 。
Python 源代碼
sub1=int(input("Enter marks of the first subject: "))
sub2=int(input("Enter marks of the second subject: "))
sub3=int(input("Enter marks of the third subject: "))
sub4=int(input("Enter marks of the fourth subject: "))
sub5=int(input("Enter marks of the fifth subject: "))
average=(sub1+sub2+sub3+sub4+sub4)/5
if average >= 90:
print("Grade: A")
elif average >= 80 and average < 90:
print("Grade: B")
elif average >= 70 and average < 80:
print("Grade: C")
elif average >= 60 and average < 70:
print("Grade: D")
else:
print("Grade: E")
輸出
Enter marks of the first subject: 80
Enter marks of the second subject: 70
Enter marks of the third subject: 90
Enter marks of the fourth subject: 60
Enter marks of the fifth subject: 74
Grade: C
原創文章,作者:簡單一點,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/128673.html