-
Notifications
You must be signed in to change notification settings - Fork 0
/
grade_function.py
87 lines (70 loc) · 2.55 KB
/
grade_function.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# 2) A program is required that accepts marks in three subjects and calculates the average mark. The program then
# assigns the student a grade based on the average mark using the grading system below.
# Average Mark Grade
# 80 – 100 A
# 70 – 80 B
# 60 – 70 C
# 50 – 60 D
# 0 – 50 E
# i) Write a program with a function called get_grade which accepts the
# average mark and returns the grade to the main function which then outputs it. (8
# marks)
# ii) Write a program with a function called grade which accepts the average mark and prints the grade.
def get_marks():
subj1 = int(input("Enter mark for subject 1: "))
subj2 = int(input("Enter marks for subject 2: "))
subj3 = int(input("Enter marks for subject 3; "))
# A program is required that accepts marks in three subjects
# and calculates the average mark. The program then assigns
# the student a grade based on the average mark using the grading system below.
# Average Mark Grade
# 80 – 100 A
# 70 – 80 B
# 60 – 70 C
# 50 – 60 D
# 0 – 50 E
# i) Write a program with a function called get_grade
# which accepts the average mark and returns the grade to
# the main function which then outputs it.
# ii) Write a program with a function called grade
# which accepts the average mark and prints the grade
def get_grade(subj1, subj2, subj3):
sum = subj1 + subj2 + subj3
return sum
def get_grade(sum):
average = sum / 3
if 80 < average <= 100:
return "A"
elif 70 < average <= 80:
return "B"
elif 60 < average <= 70:
return "C"
elif 50 < average <= 60:
return "D"
elif 0 <= average <= 50:
return "E"
return average
marks = get_marks()
grade = get_grade(marks)
print(f"The average is {round(marks / 3)} You have attained a {grade}")
def grade(sum):
average = sum / 3
if 80 < average <= 100:
print("You have an A")
elif 70 < average <= 80:
print("You have an B")
elif 60 < average <= 70:
print("You have an c")
elif 50 < average <= 60:
print("You have an D")
elif 0 <= average <= 50:
print("You have an E")
else:
print("Not on the grade system: ")
return average
subj1 = int(input("Enter subject1: "))
subj2 = int(input("Enter subject2: "))
subj3 = int(input("Enter subject3: "))
sum = int(get_grade(subj1, subj2, subj3))
average = int(grade(sum))
print(f'The sum is->{sum};\nThe average is->{average}:')