-
Notifications
You must be signed in to change notification settings - Fork 1
/
user_IO.py
67 lines (61 loc) · 3.06 KB
/
user_IO.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import exceptions
def user_input():
todo = input("Ok, do you want to see them or to edit them [see/edit/exit]?\n")
if todo == "see":
print("Which subject do you want to know the information?")
subject = input()
return "output", subject
elif todo == "edit":
print("Do you want to add a subject, a category or a grade [subject/category/grade]?")
user_add = input()
if user_add == "subject":
subject = input("Which subject do you want to add? \n")
main_subject = input("Is this subject a main subject [y/n]? \n")
if main_subject == 'y':
main_subject = True
elif main_subject == 'n':
main_subject = False
else:
raise exceptions.WrongCaseException
oral_exam = input("Will there be an oral exam in this subject [y/n]? \n")
if oral_exam == 'y':
oral_exam = True
elif oral_exam == 'n':
oral_exam = False
else:
raise exceptions.WrongCaseException
return "input", "subject", subject, main_subject, oral_exam
elif user_add == "category":
subject = input("To which subject do you want to add the category? \n")
category = input("Which category do you want to add? \n")
rating = float(input("Rating? \n"))
if exceptions.convertible(rating):
return "input", "category", subject, category, rating
elif user_add == "grade":
subject = input("To which subject do you want to add the grade? \n")
category = input("To which category do you want to add it? \n")
grade = input("Grade? \n")
grade_name = input("What's the name of the grade? \n")
if exceptions.convertible(grade):
return "input", "grade", subject, category, grade, grade_name
elif todo == "exit":
return "exit"
def user_output(subject, categories, average, average_subject):
print("\n\n In the subject {} are the following categories:".format(subject))
for counter, category in enumerate(categories):
print("The average in {} is {} with these grades:".format(category, average[counter]))
string = ""
for grade in categories[category][0]:
string += str(grade.grade) + ", "
print(string + "\n")
print("The average of {} is {}.".format(subject, average_subject))
def exception_raised(exception):
print("Dear user you've raised an exception. The cause of the exception is:")
if exception is exceptions.SubjectNotExistingException:
print("The subject you tried to access is not created")
elif exceptions is exceptions.CategoryNotExistingException:
print("The category you tried to add something is non-existent in this subject")
elif exception is exceptions.NotANumberException:
print("The number you gave the program is not a number")
elif exception is exceptions.WrongCaseException:
print("This was not one of the available choices")