I tried putting an if statement indicating distance_mi as an empty set indicating a “falsy value” and to print false if it is. This is for step 15 on building a travel weather planner. I am also attempting steps 19-23 and getting errors on those as well for some reason. What am I missing or doing wrong?
Your code so far
distance_mi = 15.3
is_raining = True
has_bike = False
has_car = True
has_ride_share_app = True
if distance_mi <= 1 and not is_raining:
print("True")
elif distance_mi == []:
print("False")
elif distance_mi > 1 and <= 6 and not has_bike and not is_raining:
print("False")
elif distance_mi > 1 and <= 6 and has_bike == True and not is_raining:
print("True")
elif distance_mi > 6 and has_ride_share_app == True:
print("True")
elif distance_mi > 6 and not has_car and not has_ride_share_app:
print("False")
else:
print("False")
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36
Challenge Information:
Build a Travel Weather Planner - Build a Travel Weather Planner
Thank you for that input, I put the following into my code to hopefully make the change and started my code over to simply get rid of all the syntax errors to help me and start over. This is what I have now and I’m focusing my attention to lines 6-8. I put distance_mi as 0 to indicate it is falsy. Then after that if statement, assigned a value to distance_mi to complete the code for the rest of the assignment, but step 15 is still giving me the message indicating that “When distance_mi is a falsy value, the program should print False.” How did I not do that according to my code between lines 6-8? TYIA!
Okay, so below is my entire code. Can you tell me why I am not passing steps 15, 16, and 17 in my code? i can’t use elif in these cases without getting an error message either.
is_raining = True
has_bike = True
has_car = True
has_ride_share_app = True
distance_mi = 4
'''step 15'''
if distance_mi == 0:
print("False")
'''step 16'''
if distance_mi <= 1 and not is_raining:
print("True")
'''step 17'''
if distance_mi <= 1 and is_raining:
print("False")
'''Step 18-23: 1 < x <= 6'''
if distance_mi > 1 and distance_mi <= 6 and is_raining and not has_bike:
print("False")
elif distance_mi > 1 and distance_mi <= 6 and not is_raining and not has_bike:
print("False")
elif distance_mi > 1 and distance_mi <= 6 and not is_raining and has_bike:
print("True")
elif distance_mi > 6 and has_ride_share_app:
print("True")
elif distance_mi > 6 and has_car:
print("True")
elif distance_mi > 6 and not has_car or not has_ride_share_app:
print("False")
Please organize your code so it only prints one thing. For example, if distance_mi is 0, your code prints False twice in the console. Does it make sense to continue processing if distance_mi is falsy? And, as I mentioned in a previous post, 0 is not the only falsy value. How can you write your code to handle any falsy value?
Okay, I see what I did. I simply just needed to make only ONE big if statement with the rest being elifstatements that satisfy the rest of the requirements. Also, for some reason it didn’t like my comments in between my code. Which is fine. I finally passed it!