-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython_Functions_and_Lists.py
More file actions
76 lines (59 loc) · 1.61 KB
/
Copy pathpython_Functions_and_Lists.py
File metadata and controls
76 lines (59 loc) · 1.61 KB
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
# ============================================
# Assignment: Python Functions and Lists
# ============================================
def calculate_total(marks):
"""
Calculate the total sum of marks in the list.
Parameters:
marks (list): List of numerical marks
Returns:
int/float: Sum of all marks
"""
total = 0
for mark in marks:
total += mark
return total
def calculate_average(marks):
"""
Calculate the average of marks using calculate_total().
Parameters:
marks (list): List of numerical marks
Returns:
float: Average of marks
"""
total = calculate_total(marks)
count = 0
for _ in marks:
count += 1
return total / count if count != 0 else 0
def get_grade(average):
"""
Determine grade based on average marks.
Parameters:
average (float): Average marks
Returns:
str: Grade (A, B, or C)
"""
if average > 90:
return "A"
elif average > 75:
return "B"
else:
return "C"
def display_report(marks):
"""
Display total, average, and grade by calling other functions.
Parameters:
marks (list): List of numerical marks
"""
total = calculate_total(marks)
average = calculate_average(marks)
grade = get_grade(average)
print(f"Total: {total}")
print(f"Average: {average}")
print(f"Grade: {grade}")
# ============================================
# Test the solution
# ============================================
marks_list = [88, 76, 95, 60, 82]
display_report(marks_list)