写一个 Python 程序,通过一个例子找到学生等级。为此,首先,我们必须计算总数和五个科目的百分比。接下来,使用 Elif 查找等级
找到学生成绩的 Python 程序
这个 python 程序允许用户为五个科目输入五个不同的值。接下来,它找到这五个科目的总数和百分比。对于这个 Python 示例,我们使用算术运算符来执行算术运算。
提示: Elif 语句检查第一个条件。如果为真,则执行该 Python 块中的语句。如果条件为假,则检查下一个条件(Elif 条件)等等。
# Python Program to find Student Grade
english = float(input(" Please enter English Marks: "))
math = float(input(" Please enter Math score: "))
computers = float(input(" Please enter Computer Marks: "))
physics = float(input(" Please enter Physics Marks: "))
chemistry = float(input(" Please enter Chemistry Marks: "))
total = english + math + computers + physics + chemistry
percentage = (total / 500) * 100
print("Total Marks = %.2f" %total)
print("Marks Percentage = %.2f" %percentage)
Python 学生级输出
Please enter English Marks: 70
Please enter Math score: 60
Please enter Computer Marks: 90
Please enter Physics Marks: 80
Please enter Chemistry Marks: 85
Total Marks = 385.00
Marks Percentage = 77.00
学生级 Python 程序示例 2
在这个 python 程序中,我们使用 Elif 语句来查找等级。
# Python Program to find Student Grade
english = float(input(" Please enter English Marks: "))
math = float(input(" Please enter Math score: "))
computers = float(input(" Please enter Computer Marks: "))
physics = float(input(" Please enter Physics Marks: "))
chemistry = float(input(" Please enter Chemistry Marks: "))
total = english + math + computers + physics + chemistry
percentage = (total / 500) * 100
print("Total Marks = %.2f" %total)
print("Marks Percentage = %.2f" %percentage)
if(percentage >= 90):
print("A Grade")
elif(percentage >= 80):
print("B Grade")
elif(percentage >= 70):
print("C Grade")
elif(percentage >= 60):
print("D Grade")
elif(percentage >= 40):
print("E Grade")
else:
print("Fail”)