我做了一个程序,用户输入学生的分数,Python 告诉平均分数,告诉我们分数是令人满意的,好还是优秀。下面给出:
from array import array as arr
import numpy as np
from tabulate import *
marks = []
stu_mks = input("Enter the marks of the students(entering STOP would end the process): ")
marks.append(stu_mks)
while stu_mks.lower() != 'stop':
stu_mks = input("Enter the marks of the students(entering STOP would end the process): ")
marks.append(stu_mks)
del marks[-1]
array_marks = np.array(marks)
float_marks = array_marks.astype(np.float)
avg = 0
for i in float_marks:
avg += i
print("The average marks are", avg / len(float_marks))
for x in float_marks:
if x % 1 == 0:
print(int(x), end = "\t")
if x < 40:
print("NOT SATISFACTORY")
if x > 40 and x <= 74:
print("SATISFACTORY")
if x >= 75 and x <= 89:
print("GOOD")
if x >= 90:
print("EXCELLENT")
else:
print(x, end = "\t")
if x < 40:
print("NOT SATISFACTORY")
if x > 40 and x <= 74:
print("SATISFACTORY")
if x >= 75 and x <= 89:
print("GOOD")
if x >= 90:
print("EXCELLENT")
我真正想要的是分数和他们的评论(即好,优秀等)以表格格式显示。这就是我导入tabulate
模块的原因,但问题是我不知道如何将每一行作为列表或字典添加到任何变量中,然后将其制成表格。我非常努力,但一切都是徒劳的。所以,请给我建议一种方法来做同样的事情,如果有更好的方法来用更少的代码行运行这个程序,那将是非常可观的。先感谢您。