Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def gather_credits(needed_credits, *courses_info):
- gathered_credits = 0
- enrolled_courses = []
- for course_name, course_credits in courses_info:
- if gathered_credits >= needed_credits:
- break
- if course_name not in enrolled_courses:
- enrolled_courses.append(course_name)
- gathered_credits += course_credits
- if gathered_credits >= needed_credits:
- return f"Enrollment finished! Maximum credits: {gathered_credits}.\nCourses: {', '.join(sorted(enrolled_courses))}"
- return f"You need to enroll in more courses! You have to gather {needed_credits - gathered_credits} credits more."
- # Example usage:
- print(gather_credits(
- 80,
- ("Basics", 27),
- ))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement