Added assignment 2 code

This commit is contained in:
K 2023-09-25 17:50:23 +05:30
parent 5560c6ba50
commit 0e25247429
Signed by: notkshitij
GPG Key ID: C5B8BC7530F8F43F

92
assignment-2.py Normal file
View File

@ -0,0 +1,92 @@
# DSL - Assignment 2
students=[]
marks=[]
total_students_in=int(input("Total number of students are: \t"))
# Entering marks
def total_students_fn():
for i in range(total_students_in):
marks_in=int(input("Enter marks for DSA subject for each student (out of 50) (enter -1 for absent students): \t"))
marks.append(marks_in)
print("Marks of", total_students_in, "students in DSA subject are:", marks)
total_students_fn()
# Option 1 = Average
def average_marks():
for i in marks:
if i<0:
break
else:
average_calc=sum(marks)/total_students_in
print("Average score of", total_students_in, "is: \t", average_calc)
# Option 2 = Highest and lowest
def high_low():
mini=marks[0]
maxi=marks[0]
for i in range (len(marks)):
if (maxi<marks[i] and marks[i]>-1):
maxi=marks[i]
for j in range (len(marks)):
if (mini>marks[j] and marks[j]>-1):
mini=marks[j]
print("Highest marks are: \t", maxi)
print("Lowest marks are: \t", mini)
# Option 3 = Absent
def absent():
absent_count=0
for i in marks:
if i==-1:
absent_count+=1
print("Total number of absent students out of", total_students_in, "are: \t", absent_count)
# Option 4 = Highest freq
def high_freq():
freq_count=0
for i in range(len(marks)):
if (i>=0):
count=0
for j in range(len(marks)):
if (marks[i]==marks[j]):
count+=1
if (freq_count<count):
freq_count=count
else:
break
print("Highest frequency is: \t", freq_count)
# Choosing an option
def choose_optn():
while True:
print("Choose an operation to perform:")
print("1. Average score of all students")
print("2. Highest and lowest score out of all students")
print("3. Count of students absent for test")
print("4. Display marks with highest frequency")
print("5. Exit")
optn=int(input("Enter option number (1-5): \t"))
if optn==1:
average_marks()
print("Designed and Engineered by Kshitij")
elif optn==2:
high_low()
print("Designed and Engineered by Kshitij")
elif optn==3:
absent()
print("Designed and Engineered by Kshitij")
elif optn==4:
high_freq()
print("Designed and Engineered by Kshitij")
elif optn==5:
print("## Designed and Engineered by Kshitij\n## END OF CODE.")
quit()
else:
print("\n Invalid option selected. Please choose from range 1 to 5. \n")
choose_optn()
choose_optn()
## END OF CODE