Advertisement
Nenogzar

03. Enrollment

Jun 20th, 2024
603
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.73 KB | None | 0 0
  1. def gather_credits(needed_credits, *courses_info):
  2.     gathered_credits = 0
  3.     enrolled_courses = []
  4.  
  5.     for course_name, course_credits in courses_info:
  6.         if gathered_credits >= needed_credits:
  7.             break
  8.         if course_name not in enrolled_courses:
  9.             enrolled_courses.append(course_name)
  10.             gathered_credits += course_credits
  11.  
  12.     if gathered_credits >= needed_credits:
  13.         return f"Enrollment finished! Maximum credits: {gathered_credits}.\nCourses: {', '.join(sorted(enrolled_courses))}"
  14.    
  15.     return f"You need to enroll in more courses! You have to gather {needed_credits - gathered_credits} credits more."
  16.  
  17. # Example usage:
  18. print(gather_credits(
  19.     80,
  20.     ("Basics", 27),
  21. ))
  22.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement