exceptions added for user input

This commit is contained in:
2019-08-02 18:54:27 +02:00
parent 0cb5e2f73f
commit caf650eaef
4 changed files with 91 additions and 33 deletions
+23 -2
View File
@@ -1,3 +1,6 @@
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":
@@ -14,23 +17,29 @@ def user_input():
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"))
return "input", "category", subject, category, rating
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")
return "input", "grade", subject, category, grade, grade_name
if exceptions.convertible(grade):
return "input", "grade", subject, category, grade, grade_name
elif todo == "exit":
return "exit"
@@ -49,3 +58,15 @@ def user_output(subject, categories, average, average_subject):
def password():
print("What is your password?")
return input()
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")