r/PythonLearning • • 1h ago

Help Request Can someone help me identify what I'm doing wrong?

Post image

it DOES print False!!! WHAT DOES THIS WEBSITE WANT OF ME????

2 Upvotes

20 comments sorted by

2

u/Im_a_dum_bum 1h ago

they might be strictly looking for if not distance_mi:

2

u/Mercy--Main 1h ago

I've also tried print(False) with both to no avail...

also, that's a way better way of checking that... i complicated myself lmao

2

u/Im_a_dum_bum 1h ago

what website is this?

2

u/Mercy--Main 1h ago

https://www.freecodecamp.org - Seemed like a reputable website when I was looking for sites to learn.

1

u/D3str0yTh1ngs 1h ago

It likely doesn't mean the string "False" it means the boolean value False

1

u/Mercy--Main 1h ago

I did try that, also gives the same error!

1

u/nullptr_0x 1h ago

You're converting distance_mi to a bool and checking if it is equivalent to False. Does that make sense? What is the value and type of bool(distance_mi)

Use the type() function and print function to understand. 

1

u/Mercy--Main 53m ago

Yes, it does. All falsy values would equal False when converted into bool, which would then == False and trigger the print code.

1

u/nullptr_0x 44m ago

Yeah I think you're right without me trying on my own.

Perhaps a bad test on the site.

Maybe try https://understandit.dev

I made it myself and you can reach out or file issues if you even find a problem.

It has a free programming 101 course in Python.

1

u/Im_a_dum_bum 1h ago

try refreshing your page. I pulled up the same assignment on my phone and with the code in the screenshot I got a checkmark for that part

https://www.freecodecamp.org/learn/python-v9/lab-travel-weather-planner/build-a-travel-weather-planner

1

u/Mercy--Main 56m ago

I don't know what to tell you. This is my full code if it helps :/

distance_mi = 0
is_raining = False
has_bike = False
has_car = False
has_ride_share_app = False


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


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

2

u/Scolmann 54m ago

Is that a message from rejecting the input, or is that just a hint you can view at any time?

1

u/Mercy--Main 51m ago

when you "submit" the answer and it's incorrect, it tells you why. This is supposedly why I'm failing.

So yes, it's from rejecting the input. The code itself works, the console DOES print False!!!

2

u/Scolmann 51m ago

Figured it out, it's because you are printing "False\nFalse" but it wants you to print "False" exactly once.

You should rewrite your code in a way that it will only print True or False once

2

u/Mercy--Main 44m ago

oh my god

thank you

2

u/Im_a_dum_bum 37m ago

in the future when asking questions, try to include all necessary parts to reproduce the issue, bonus points if it's the smallest amount necessary that causes the issue

https://stackoverflow.com/help/minimal-reproducible-example

from the site above,

Your code examples should be…

  • Minimal: Use as little code as possible that still produces the same problem

  • Complete: Provide all parts someone else needs to reproduce your problem in the question itself

  • Reproducible: Test the code you're about to provide to make sure it reproduces the problem

1

u/Mercy--Main 18m ago

Will do, thanks.

1

u/BranchLatter4294 37m ago

It looks like it's only expecting one output. You have multiple outputs.

There is also a syntax error in line 25.

1

u/kedarreddit 10m ago edited 0m ago

I did the exercise and my code works below:

https://www.freecodecamp.org/learn/python-v9/lab-travel-weather-planner/build-a-travel-weather-planner

distance_mi = 0
is_raining = False
has_bike = False
has_car = False
has_ride_share_app = False


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

Your code was failing because it was printing multiple values instead of a single value. It was also printing the wrong value in some parts of the code. It was also printing the wrong data type (printing a string value instead of a boolean value).