-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathA2.py
executable file
·170 lines (120 loc) · 4.49 KB
/
A2.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
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# DSL – ASSIGNMENT 1 – A2
class Test:
def __init__(self):
self.fds = []
self.n = 0
def getdata(self):
self.n = int(input('\nEnter the class strength of SE Comp A: '))
print('\n(Note: Enter -1 for absent students)\n')
print('---------------------------------------------------------')
print('Enter the marks scored in Fundamental of Data Structure: ')
print('---------------------------------------------------------\n\n')
for i in range(self.n):
self.fds.append(int(input(f'Enter marks of roll no {i + 1}: ')))
def putdata(self):
print('\n\nTest Marks of Fundamental of Data Structure are as follows...\n')
print('*********************************')
print('| Roll No | DSA Marks |')
print('*********************************')
for i in range(self.n):
print(f'|\t{i + 1}\t|\t{self.fds[i]}\t|')
print('---------------------------------\n\n')
def avg(self):
total = 0
present = 0
for i in self.fds:
if i != -1:
total += i
present += 1
print(f'Average marks of the class: {round(total / present, 3)}\n\n')
def absstud(self):
print('Students absent for Fundamental of Data Structure test are: \n')
absent = 0
for i in range(self.n):
if self.fds[i] == -1:
print(f'Roll No: {i + 1} absent')
absent += 1
print(f'\nTotal absent students are: {absent}\n\n')
def maxmin(self):
maxi, max_rollno, mini, min_rollno = 0, [], 10, []
for i, val in enumerate(self.fds):
if val != -1:
if maxi == val:
max_rollno.append(i + 1)
elif maxi < val:
max_rollno = [i + 1]
maxi = val
if mini == val:
min_rollno.append(i + 1)
elif mini >= val:
min_rollno = [i + 1]
mini = val
max_rollno, min_rollno = ', '.join(map(str, max_rollno)), ', '.join(map(str, min_rollno))
print(f'Highest Test Score : Roll No : ({max_rollno}) with Marks = {maxi}\n')
print(f'Lowest Test Score : Roll No : ({min_rollno}) with Marks = {mini}\n\n')
def frequency(self):
max_marks = 10
freq = [0] * (max_marks + 1)
stud, marks, index = 0, 0, []
for val in self.fds:
if val != -1:
freq[val] += 1
for i, val in enumerate(freq):
if stud <= val:
marks = i
stud = val
for i, val in enumerate(self.fds):
if val == marks:
index.append(i + 1)
index = ', '.join(map(str, index))
print(f'Maximum of {marks} marks are scored by {stud} students with Roll No: ({index})')
def main():
test = Test()
test.getdata()
test.putdata()
test.avg()
test.absstud()
test.maxmin()
test.frequency()
if __name__ == "__main__":
main()
"""
----------------- OUTPUT -----------------
Enter the class strength of SE Comp A: 10
(Note: Enter -1 for absent students)
---------------------------------------------------------
Enter the marks scored in Fundamental of Data Structure:
---------------------------------------------------------
Enter marks of roll no 1: 2
Enter marks of roll no 2: 5
Enter marks of roll no 3: -1
Enter marks of roll no 4: 4
Enter marks of roll no 5: 2
Enter marks of roll no 6: 10
Enter marks of roll no 7: 6
Enter marks of roll no 8: 4
Enter marks of roll no 9: 10
Enter marks of roll no 10: 4
Test Marks of Fundamental of Data Structure are as follows...
*********************************
| Roll No | DSA Marks |
*********************************
| 1 | 2 |
| 2 | 5 |
| 3 | -1 |
| 4 | 4 |
| 5 | 2 |
| 6 | 10 |
| 7 | 6 |
| 8 | 4 |
| 9 | 10 |
| 10 | 4 |
---------------------------------
Average marks of the class: 5.222
Students absent for Fundamental of Data Structure test are:
Roll No: 3 absent
Total absent students are: 1
Highest Test Score : Roll No : (6, 9) with Marks = 10
Lowest Test Score : Roll No : (1, 5) with Marks = 2
Maximum of 4 marks are scored by 3 students with Roll No: (4, 8, 10)
"""