I was instructed to make a program to determine the hurricane category based on the wind speed

Hello my teacher assigned us a assignment where the program must calculate the category of hurricane based on wind speed. THE PROGRAM IS NO FINISHED it has 5 category's but I have only gotten this far because I CANT FIGURE OUT WHY when the program asks for the wind input I put 95 and then nothing happens. But if I type 67 it will print 0 which is good. but why wont it do It for the other? I want it to print 1 but I'm missing something. these are If then statements by the way. Also please don't comment on my post with useless comments... I'm just trying to understand my programming homework thanks you.

#hurricane weather 
#Category = int(input("Wind speed mph: "))

windspeed = int(input("Ask for wind speed: "))

if windspeed > 64 and windspeed < 76:
    print("0")
if windspeed > 65 and windspeed < 85:
    print("Hurricane category: ")
    else:
        if windspeed > 85 and windspeed < 111:
            print("1")
            if windspeed > 86 and windspeed <110:
                print("Hurricane category: ")

1 answer

  • answered 2018-02-13 01:32 Moller Rodrigues

    Hey bro looks like you are getting confused with how to write if statements. In your current code your condition which relates to the input of 95 is within the if statement for whether the users input is between 65 and 85. As 95 is not within this range it cannot continue past this point and so it wont run your else statement as it is within the if statement.

    your code:

    if windspeed > 65 and windspeed < 85:
        print("Hurricane category: ")
        else: # see here you put the else satement within the if statement
            if windspeed > 85 and windspeed < 111:
    

    to fix your code it should be like this:

    if windspeed > 65 and windspeed < 85:
         print("Hurricane category: ")
    else:
         if windspeed > 85 and windspeed < 111:
    
     # if and else should be at the same indentation
    

    But what you should really be using is elif which means else if for example:

    windspeed = int(input("Ask for wind speed: "))
    
    if windspeed > 64 and windspeed < 76:
        print("0")
    elif windspeed > 65 and windspeed < 85:
        print("Hurricane category: ")
    elif  windspeed > 85 and windspeed < 111:
        print("1")
    elif windspeed > 86 and windspeed <110:
        print("Hurricane category: ")