Advertisement
horozov86

Student Credits

Jun 11th, 2023
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.04 KB | None | 0 0
  1. def students_credits(*args):
  2.     dictionary = {}
  3.     credits_collected = 0
  4.     for course in args:
  5.         course_split = course.split('-')
  6.         course_name = course_split[0]
  7.         max_course_credits = int(course_split[1])
  8.         max_test_points = int(course_split[2])
  9.         diyan_points = int(course_split[3])
  10.         percentage_test_diyan = diyan_points/max_test_points
  11.         current_diyan_credit = max_course_credits * percentage_test_diyan
  12.         credits_collected += current_diyan_credit
  13.         dictionary[course_name] = current_diyan_credit
  14.      
  15.     result = ''    
  16.     if credits_collected >= 240:
  17.         result += f"Diyan gets a diploma with {credits_collected:.1f} credits.\n"
  18.        
  19.     else:
  20.         diff = 240 - credits_collected
  21.         result += f"Diyan needs {diff:.1f} credits more for a diploma.\n"
  22.        
  23.     sorted_dictionary = dict(sorted(dictionary.items(), key=lambda x: -x[1]))
  24.    
  25.     for el, score in sorted_dictionary.items():
  26.         result += f'{el} - {score:.1f}\n'
  27.        
  28.     return result
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement