sidrs

FDS (LV) Ass 2

Aug 5th, 2024 (edited)
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.68 KB | None | 0 0
  1. n = int(input("Enter Number of Students: "))
  2. marks = {}
  3. for i in range(1, n+1):
  4.     marks[i] = input("Enter the marks for Roll Number " + str(i) + ": ")
  5.    
  6.  
  7. print("\nThe Marks are as Follows: ")
  8. for roll, mark in marks.items():
  9.     print("SB" + str(roll) + ": " + str(mark))
  10.  
  11. def getAverage():
  12.     sum = 0
  13.     for value in marks.values():
  14.         if value == "AB":
  15.             continue    
  16.         sum += int(value)
  17.     average = sum/n
  18.     print("\nThe Average Score is: " + str(average))
  19.    
  20.  
  21. def getExtremes():
  22.     maximum = 0
  23.     minimum = 100
  24.     for value in marks.values():
  25.         if value == "AB":
  26.             continue
  27.         else:
  28.             value = int(value)
  29.             if value >= maximum:
  30.                 maximum = value
  31.             if value <= minimum:
  32.                 minimum = value
  33.     print("\nThe Maximum score is: " + str(maximum))
  34.     print("\nThe Minumum score is: " + str(minimum))
  35.  
  36.  
  37. def getAbsentCount():
  38.     count = 0
  39.     for value in marks.values():
  40.         if value == "AB":
  41.             count += 1
  42.     print("\nNumber of students who were Absent is: " + str(count))
  43.  
  44.  
  45. def getHighestFrequency():
  46.     justMarks = []
  47.     distinct = []
  48.     frequencies = {}
  49.     markCount = 0
  50.    
  51.     for value in marks.values():
  52.         if value == "AB":
  53.             continue
  54.         else:
  55.             value = int(value)
  56.             justMarks.append(value)
  57.             if value not in distinct:
  58.                 distinct.append(value)
  59.                
  60.     for element in distinct:
  61.         markCount = 0
  62.         for mark in justMarks:
  63.             if mark == element:
  64.                 markCount += 1
  65.         frequencies[element] = markCount
  66.  
  67.     maxFreq = 0
  68.     freqMark = 0
  69.     print()
  70.     for mark, freq in frequencies.items():
  71.         if freq >= maxFreq:
  72.             maxFreq = freq
  73.             freqMark = mark
  74.     print("Mark of " + str(freqMark) + " has the highest frequency of: " + str(maxFreq))
  75.    
  76.        
  77.  
  78. print ("\n ---------- MENU ----------")
  79. while True:
  80.     print("\nChoose a Task Number from 1, 2, 3, 4, 5")
  81.     print("1: Get Average Score of the class")
  82.     print("2: Get the Maximum and Minumum Scores")
  83.     print("3: Get count of Absent Students")
  84.     print("4: Get the Mark with Highest Frequency")
  85.     print("5: Exit")
  86.     choice = (input("Enter the Task Number: "))
  87.    
  88.     if choice == '1':
  89.         getAverage()
  90.        
  91.     elif choice == '2':
  92.         getExtremes()
  93.        
  94.     elif choice == '3':
  95.         getAbsentCount()
  96.        
  97.     elif choice == '4':
  98.         getHighestFrequency()
  99.        
  100.     elif choice == '5':
  101.         break
  102.        
  103.     else:
  104.         print("\nERROR! Enter a valid choice")
Advertisement
Add Comment
Please, Sign In to add comment