Build a Travel Weather Planner - Build a Travel Weather Planner

Tell us what’s happening:

on the second distance check on the travel weather planner my code fails. I’ve completely deleted and started over from scratch - with the same results. The tests fail at step 19 on. There is something ambiguous going on that I’m not able to pin down. Any help would be greatly appreciated.

Your code so far

distance_mi = 2
is_raining = True
has_bike = True
has_car = True
has_ride_share_app = True

if distance_mi > 0:
    if distance_mi <= 1 and is_raining == False:
        print('True')
    else:
        print('False')
elif distance_mi > 1 and distance_mi <= 6:
    if has_bike == True and is_raining == False:
        print('True')
    else:
        print('False')
else:
    if distance_mi > 6:
        if has_car == True or has_ride_share_app == True:
            print('True')
    else:
        print('False')


Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:147.0) Gecko/20100101 Firefox/147.0

Challenge Information:

Build a Travel Weather Planner - Build a Travel Weather Planner

Just redid the code with a second elif and an ending else to catch if the distance is falsy (not greater than 0), getting the same error messages on the first elif statement for the check between 1 and 6.

do you understand that only one statement in a chain is going to run?

so if this is true

this will not run:

and the else will also not run

1 Like

oh, so i think I’m getting it. If I’m understanding you correctly, the code does not drop down and execute every elif, rather when there is either a success or fail it prints the one message, and then drops out of the entire if structure, and ends the program?

It’s been a hot minute since I’ve coded anything and I’m a little embarrassed at missing glaring logic fails.

in a if/elif/elif…/else chain the first one that is true is executed

in your code that is the one with condition distance_mi > 0
so only this block is executed:

these are not:

After a function resulting from any if else condition being met (regardless if true or false), the entire program ends correct?

It is difficult to get exact question across.

if there is other code after the if/elif/else chain, that code will continue

if True:
    print("I get printed")
elif True:
    print("I don't get printed")
else:
    print("I don't get printed")

print("I also get printed")

so, no, the entire program does not end

1 Like

the correct was with my options:

code removed by moderator

hi @Hana_R

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge. How to Help Someone with Their Code Using the Socratic Method

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.