Skip to content

Instantly share code, notes, and snippets.

@edipetres
Created March 27, 2018 15:18
Show Gist options
  • Save edipetres/d84e9dafedbd842e8718a462de74d688 to your computer and use it in GitHub Desktop.
Save edipetres/d84e9dafedbd842e8718a462de74d688 to your computer and use it in GitHub Desktop.
Algorithms Compulsory Assignment 2 - trees
RESP_GOOD = 'You should be able to pass the exam.'
RESP_BAD = 'You could easily fail the exam.'
def decision_tree():
hand_ins_made_on_time = get_answer("Hand-ins made on time?")
if hand_ins_made_on_time == True:
attend_lectures = get_answer('Attended lectures?')
make_exercise = get_answer('Did you make the exercises?')
read_textbook = get_answer('Did you read the textbook?')
if attend_lectures == False:
if make_exercise == False or read_textbook == False:
return print(RESP_BAD)
return print(RESP_GOOD)
else:
return print(RESP_BAD)
# Asks the user a question and returns True or False based on the result
def get_answer(question):
res = input(question + ' (y/n)\n')
if res == 'y' or res == 'yes':
return True
elif res == 'n' or res == 'no':
return False
else:
raise Exception('Wrong value given.')
decision_tree()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment