Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- n = int(input("Enter Number of Students: "))
- marks = {}
- for i in range(1, n+1):
- marks[i] = input("Enter the marks for Roll Number " + str(i) + ": ")
- print("\nThe Marks are as Follows: ")
- for roll, mark in marks.items():
- print("SB" + str(roll) + ": " + str(mark))
- def getAverage():
- sum = 0
- for value in marks.values():
- if value == "AB":
- continue
- sum += int(value)
- average = sum/n
- print("\nThe Average Score is: " + str(average))
- def getExtremes():
- maximum = 0
- minimum = 100
- for value in marks.values():
- if value == "AB":
- continue
- else:
- value = int(value)
- if value >= maximum:
- maximum = value
- if value <= minimum:
- minimum = value
- print("\nThe Maximum score is: " + str(maximum))
- print("\nThe Minumum score is: " + str(minimum))
- def getAbsentCount():
- count = 0
- for value in marks.values():
- if value == "AB":
- count += 1
- print("\nNumber of students who were Absent is: " + str(count))
- def getHighestFrequency():
- justMarks = []
- distinct = []
- frequencies = {}
- markCount = 0
- for value in marks.values():
- if value == "AB":
- continue
- else:
- value = int(value)
- justMarks.append(value)
- if value not in distinct:
- distinct.append(value)
- for element in distinct:
- markCount = 0
- for mark in justMarks:
- if mark == element:
- markCount += 1
- frequencies[element] = markCount
- maxFreq = 0
- freqMark = 0
- print()
- for mark, freq in frequencies.items():
- if freq >= maxFreq:
- maxFreq = freq
- freqMark = mark
- print("Mark of " + str(freqMark) + " has the highest frequency of: " + str(maxFreq))
- print ("\n ---------- MENU ----------")
- while True:
- print("\nChoose a Task Number from 1, 2, 3, 4, 5")
- print("1: Get Average Score of the class")
- print("2: Get the Maximum and Minumum Scores")
- print("3: Get count of Absent Students")
- print("4: Get the Mark with Highest Frequency")
- print("5: Exit")
- choice = (input("Enter the Task Number: "))
- if choice == '1':
- getAverage()
- elif choice == '2':
- getExtremes()
- elif choice == '3':
- getAbsentCount()
- elif choice == '4':
- getHighestFrequency()
- elif choice == '5':
- break
- else:
- print("\nERROR! Enter a valid choice")
Advertisement
Add Comment
Please, Sign In to add comment