0

Saying "n" to "Do you have a fever?" outputs False instead of prompting me for an answer to "Do you have a stuffy nose?". The other else statements work. Saying "y" to "Do you have a fever?", "n" to "Do you have a rash?", and "n" to "Does your ear hurt?" prints "Flu". I can't figure out why that one else statement doesn't work.

def part3():
    if(raw_input("Do you have a fever? (y/n): ") == "y"):
        if(raw_input("Do you have a rash? (y/n): ") == "y"):
            print "Measles"
        else:
            if(raw_input("Does your ear hurt? (y/n): ") == "y"):
                print "Ear Infection"
            else:
                print "Flu" 
    else:
        if(raw_input("Do you have a stuffy nose? (y/n): " == "y")):
            print "Head Cold"
        else:
            print "Hypochondriac"
11
  • 2
    Variables exist for a reason... Just an FYI... It let's you break down code and then do small, easily legible tasks that prevent errors like this. Jul 1, 2015 at 5:53
  • elif is a thing btw
    – Huey
    Jul 1, 2015 at 6:05
  • @Huey why elif when there are only two options? Jul 1, 2015 at 7:43
  • You have an else: hypochondriac.
    – Huey
    Jul 1, 2015 at 7:44
  • @AlexanderHuszagh I'm never reusing the variables though Jul 1, 2015 at 7:44

1 Answer 1

10

I found your mistake, and you are gonna hate yourself for it. This line

if(raw_input("Do you have a stuffy nose? (y/n): " == "y")):

should be

if(raw_input("Do you have a stuffy nose? (y/n): ") == "y"):

To explain a little more about why it printed false: "Do you have a stuffy nose? (y/n): " == "y" is evaluated to False, so it is like saying raw_input(False) which will print "False", but still get input

1
  • I'm so glad. I thought it was an obscure Python thing that I didn't know about. Phew. Jul 1, 2015 at 7:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.