Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- def get_course_name(data):
- valid = []
- pattern = "[A-Za-z]+"
- for el in data:
- match = " ".join(re.findall(pattern, el))
- valid.append(match)
- return valid
- def get_course_grades(data):
- valid = []
- pattern = "\-[A-Za-z]|\d+"
- for el in data:
- match = " ".join(re.findall(pattern, el))
- valid.append(match)
- return valid
- def students_credits(*data):
- course_names = get_course_name(data)
- course_grades = get_course_grades(data)
- student_info = {}
- for el in range(len(course_names)):
- student_info[course_names[el]] = [int(x) for x in course_grades[el].split()]
- # actual logic for the calculations (start on the following line)
- course_and_credits_info = {}
- total_student_credits = 0
- for course, grade in student_info.items():
- course_credits = grade[0]
- total_points = grade[1]
- student_points = grade[2]
- percentage = student_points / total_points
- student_credits = course_credits * percentage
- course_and_credits_info[course] = student_credits
- total_student_credits += student_credits
- sorted_course_and_credits_info = dict(sorted(course_and_credits_info.items(), key=lambda x: -x[1]))
- if total_student_credits >= 240:
- print(f"Diyan gets a diploma with {total_student_credits:.1f} credits.")
- else:
- print(f"Diyan needs {240 - total_student_credits:.1f} credits more for a diploma.")
- return '\n'.join([f"{k} - {v:.1f}" for k, v in sorted_course_and_credits_info.items()])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement