Lesson 4: Nested ifs

posted Oct 26, 2017, 7:46 AM by Attila Lengyel   [ updated Oct 26, 2017, 7:58 AM ]
print("Please wait in the room!")
print("How are you doing?")
answer = input("Do you have a fever? (y/n):")
if answer == "y":
  answer = input("Do you have throat ache? (y/n):")
  if answer == "y":
    answer = input("Do you have running nose? (y/n):")
    if answer == "y":
      print("You have caught a cold!")
      print("Please take Tylenol and take rest")
    elif answer == "n":
      print("Stay home! Soon your nose is going to run!")
    else:
      print("Please answer y or n!")
  elif answer == "n":
    print("Let me think about it...")
  else:
    print("Please answer y or n!")
elif answer == "n":
  answer = input("Do you have stomachache? (y/n)")
  if answer == "y":
    print("You must have stomach flu!")
    print("Go home, rest and drink fluids!")
  elif answer == "n":
    print("Let me think about it...")
  else:
    print("Please answer y or n!")
else:
  print("Please answer y or n!")



Comments