-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssignment_01.py
More file actions
148 lines (129 loc) · 3.98 KB
/
Assignment_01.py
File metadata and controls
148 lines (129 loc) · 3.98 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
"""
###################################
DSL Lab Assignment 1
Chaitanya Nitin Pawar SE B 48
Date : 22/8/2020
###################################
**********************Problem Statement*********************
Write a Python program to store marks scored in subject
“Fundamental of Data Structure” by N students in the
class. Write functions to compute following:
a) The average score of class
b) Highest score and lowest score of class
c) Count of students who were absent for the test
d) Display mark with highest frequency
"""
########### Reading strength of class ###########
strength = int(input("Enter total number of students::"))
marks = []
########### Reading marks of student ###########
print("\nNOTE : Enter '-1' for absent students")
for stud in range(strength):
mark = int(input("Enter the marks of student in FDS: "))
marks.append(mark)
########### Printing marks of student ###########
print("The student gets marks in FDS test are as follows...")
print(marks)
########### Main Menu ###########
def mainMenu():
print("1. The average score of class")
print("2. Highest score and lowest score of class")
print("3. Count of students who were absent for the test")
print("4. Display mark with highest frequency")
print("5. Exit")
ch = int(input("Enter Your Choice::"))
if ch == 1:
print("1. The average score of class")
avgScore()
continuous()
elif ch == 2:
print("2. Highest score and lowest score of class")
highScore()
lowScore()
continuous()
elif ch == 3:
print("3. Count of students who were absent for the test")
print("\nNOTE : Enter '-1' for absent students")
absntStud()
continuous()
elif ch == 4:
print("4. Display mark with highest frequency")
freqHigh()
continuous()
elif ch == 5:
exit()
else:
print("Enter Valid Choice")
mainMenu()
########### Function to abort the program ###########
def exit():
print("Program Exited. Thanks For Using My Program")
########### Function to calculate average marks ###########
def avgScore():
cnt = 0
Avg = 0
Total = 0
n = len(marks)
for x in marks:
if x == -1:
cnt += 1
else:
Total = Total+x
Avg = Total/(n-cnt)
print("The Average Score Of Class Is::", Avg)
########### Function to Calculate Maximum marks ###########
def highScore():
cnt = 0
max = 0
for x in marks:
if x == -1:
cnt += 1
elif x > max:
max = x
print("Highest Marks in FDS test is::", max)
########### Function to Calculate Minimum marks ###########
def lowScore():
cnt = 0
min = 100
for x in marks:
if x == -1:
cnt += 1
elif x < min:
min = x
print("Lowest Marks in FDS test is::", min)
########### Function to finding number of absent students ###########
def absntStud():
absnt = 0
for x in marks:
if x == -1:
absnt += 1
print("Count of students who were absent for the test is", absnt)
########### Function to finding highest frequency of marks ###########
def freqHigh():
max = 0
res = marks[0]
for i in marks:
if i == -1:
pass
else:
freq = marks.count(i)
if freq > max:
max = freq
res = i
op = "The Most Frequent Number is {}, and its frequency is {}".format(
str(res), max)
print(op)
########### Function to Ask whether to continue or not ###########
def continuous():
print("Do you want to continue?")
print("1. Yes")
print("2. No")
cont=int(input())
if cont == 1:
mainMenu()
elif cont == 2:
exit()
else:
print("Enter A Valid Choice")
if __name__ == "__main__":
mainMenu()