对于这个作业,我们应该在 Python 中开设一门课程,我们输入 3 个分数,并且必须找到学生的平均成绩和成绩。它有效,但我有一个错误。当我输入一个整数(例如 73)三次时,它会显示字母等级。但是当我输入一个带小数的数字(例如 83.7)三次时,它不会显示字母等级,这就是我们需要的数字。当我输入带小数的数字时,有没有办法让它显示成绩?为什么它只适用于整数?
class grades:
def __init__(self,name,test1,test2,test3,avg):
self.name = name
self.test1 = test1
self.test2 = test2
self.test3 = test3
self.avg = avg
def getName(self):
return self.name
def getTest1(self):
return self.test1
def getTest2(self):
return self.test2
def getTest3(self):
return self.test3
def getAvg(self):
return self.avg
#main:
name = input("Enter the students name: ")
test1 = float(input("Enter the first score: "))
test2 = float(input("Enter the second score: "))
test3 = float(input("Enter the third score: "))
avg = float(test1 + test2 + test3) /3.0
grades1 = grades(name,test1,test2,test3,avg)
grades1.name
grades1.test1
grades1.test2
grades1.test3
grades1.avg
print("The student's name is:" ,grades1.name)
print(grades1.name +"'s test scores are:")
print("---------------------------:")
print("TEST1: \t\t\t",grades1.test1)
print("TEST2: \t\t\t",grades1.test2)
print("TEST3: \t\t\t",grades1.test3)
print(grades1.name +"'s average is: \t",grades1.avg)
##if avg <= 100.0 and avg >= 90.0:
## print(name +"'s grade is: \t A")
##elif avg <= 89.0 and avg >= 80.0:
## print(name +"'s grade is: \t B")
##elif avg <= 79.0 and avg >= 70.0:
## print(name +"'s grade is: \t C")
##elif avg <= 69.0 and avg >= 60.0:
## print(name +"'s grade is: \t D")
##elif avg <= 59.0 and avg >= 0.0:
## print(name +"'s grade is: \t E")
if avg >= 90.0 and avg <= 100.0:
print(name +"'s grade is: \t A")
elif avg >= 80.0 and avg <= 89.0:
print(name +"'s grade is: \t B")
elif avg >= 70.0 and avg <= 79.0:
print(name +"'s grade is: \t C")
elif avg >= 60.0 and avg <= 69.0:
print(name +"'s grade is: \t D")
elif avg >= 0.0 and avg <= 59.0:
print(name +"'s grade is: \t E")
我之所以评论一年级部分是因为我尝试了两种方式都没有运气。
这是我尝试过的,但小数点没有运气
Enter the students name: k
Enter the first score: 89.9
Enter the second score: 89.9
Enter the third score: 89.9
The student's name is: k
k's test scores are:
---------------------------:
TEST1: 89.9
TEST2: 89.9
TEST3: 89.9
k's average is: 89.90000000000002