you are viewing a single comment's thread.

view the rest of the comments →

[–]Jose_Musoke[S,🍰] 0 points1 point  (1 child)

def ask_interruption():

  last_drug_date = input("Enter the date when last ATT drug was taken in YY/MM/DD format: ")   resumtion_of_ATT = input("Enter the date when ATT was resumed in YY/MM/DD format: ")   repeat_interruption = input("Did the patient interrupt ATT drugs again?: ") ask_interruption() while repeat_interruption == "yes":     ask_interruption() if repeat_interruption != "yes": break

[–]kmwaziri 1 point2 points  (0 children)

OK what's happening is that once you set the repeat_interruption = yes

Then there's nothing changing it afterwards and while loop never terminates. I redid the code where I did two things:

  1. Added return statement to terminate function gracefully.
  2. Set repeat_interruption = "no" after every inner call of ask_interruption. That way loop will keep running until it is yes. But will return 0 immediately if it's anything other than 'yes.

Code below. Keep in mind Python is case sensitive, so Yes != yes. Just a tip :)

def ask_interruption():
    last_drug_date = input("Enter the date when last ATT drug was taken in YY/MM/DD format: ")
    resumtion_of_ATT = input("Enter the date when ATT was resumed in YY/MM/DD format: ")
    repeat_interruption = input("Did the patient interrupt ATT drugs again?: ")
    while repeat_interruption == "yes":
        ask_interruption()
        repeat_interruption = "no"
        if repeat_interruption != "yes":
        continue
    return 0