In: Computer Science
This task is solved in Python 3.
Develop a program that can, among other things, manage your courses and course results.
It must also be able to calculate the average grade, for all grades or for a selection of grades
limited to a certain subject area and / or course level (100, 200 or 300 level).
NB! All courses are worth the same amount of credits.
The program should have two global collections
All courses belong to a subject area and have a course code that starts with at least three letters and always ends with three digits, of which the first digit is 1, 2 or 3 which indicates the level of the course.
Grades = {"INFO100": "C", "INFO104": "B", "ECON100": "B",…}
(All courses registered in Grades must be found in Courses, but not necessarily vice versa.)
The program should let the user select action from a menu and continue until the user chooses to exit.
The purpose of the program is for you to be able to calculate your grade points, in total and for granted subject areas and / or levels. In addition, you should be able to add new courses and set / change grades temporarily so you can experiment with how improved and upcoming results will give an effect on the grade point average.
Try to make the program robust for errors on the part of the user, such as entering a rating in form of a number, or a letter outside A-F.
On the next page you will find a guiding example of what the dialogue can look like:
>>> start ()
--------------------
1 Course list
2 Add course
3 Grade
4 Grade point average
5 Exit
--------------------
Choose action (0 for menu)> 1
Choose course and / or course level (<enter> for all)
- Course:
- Level:
INFO100 C
INFO104 B
INFO125 B
INFO132 A
INFO180
INFO216 A
INFO282 C
INFO284
ECON100 C
ECON110 C
ECON218
GE0100
GEO113 D
GEO124 D
Choose action (0 for menu)> 2
New course: ECON221
Choose action (0 for menu)> 1
Choose course and / or course level (<enter> for all)
- Course: Economics
- Level: 200
ECON218
ECON221
Choose action (0 for menu)> 3
Course: INFO284
Grade (<enter> to delete): B
Choose action (0 for menu)> 4
Choose course and / or course level (<enter> for all)
- Course: Information science
- Level: 100
Average: B
Choose action (0 for menu)> 4
Choose course and / or course level (<enter> for all)
- Course:
- Level:
Average: C
Choose action (0 for menu)> 0
--------------------
1 Course list
2 Add course
3 Grades
4 Grade point average
5 Exit
--------------------
Choose action (0 for menu)> 3
Course: GEO124
Grade (<enter> to delete): A
Choose action (0 for menu)> 4
Choose course and / or course level (<enter> for all)
- Course:
- Level:
Grade point average: B
Select action (0 for menu)> 5
Thanks for now
>>>
Courses = []
Grades = {}
def menu():
print('1 Course list')
print('2 Add course')
print('3 Grade')
print('4 Grade point average')
print('5 Exit')
def view():
print('Choose course and/or course level(<enter> for
all)')
course = input('- Course: ')
level = input('- Level: ')
flag = False
for i in Courses:
if course == '' or course[:3].upper() in i:
if not level or level[0] == i[-3]:
grade = Grades.get(i)
if not grade:
grade = ''
flag = True
print(i,grade)
if not flag:
print('Course not found')
def add():
while True:
course = input("New course: ")
if len(course)>=6:
code = course[:-3]
if course[-3:].isdigit() and len(code)>=3:
if code.isalpha() and code.isupper():
break
print('Please enter a valid course')
Courses.append(course)
def grade():
course = input("Course: ")
grade = input('Grade (<enter> to delete): ')
if grade:
if course in Courses:
Grades[course] = grade
else:
print("Please add course first")
else:
try:
del Grades[course]
except:
print('Already unassigned')
def average():
print('Choose course and/or course level(<enter> for
all)')
course = input('- Course: ')
level = input('- Level: ')
selection = []
for i in Courses:
if course == '' or course[:3].upper() in i:
if not level or level[0] == i[-3]:
grade = Grades.get(i)
if grade:
k = 'FEDCBA'.index(grade)
selection.append(k*16.67)
if selection:
avg = sum(selection)/len(selection)
grade = 'FEDCBA'[round(avg/16.67)]
print("Average:",grade)
else:
print("Grades not assigned")
def start():
menu()
while True:
try:
ch = int(input('Choose action (0 for menu)> '))
except:
print('Invalid input. Please enter number from 0-5')
continue
if ch==0:
menu()
elif ch==1:
view()
elif ch==2:
add()
elif ch==3:
grade()
elif ch==4:
average()
elif ch==5:
print('Thanks for now')
break
else:
print('Please enter number from 0-5')