Help! what's wrong with my code?

Hi everyone, I’m a beginner at Python and taking an online course. I submitted a task like below but the system always said it was wrong. Would anyone help me to check what is wrong? I checked 3 times but I still have no clue… so frustrated :frowning:

Many thanks

Please post code as text inline instead of as a screenshot. Likewise
with any program output. There’s a </> button in the compose bar to
help with this.

The question’s a little loosely worded. The final task says: “If the age
is valid, negate the variable can-drive and assign the result to a new
variable cannot_drive.” That does seem to be nearly what you’ve done.

However I expect they mean to negate can_drive itself so that it is no
longer False. Then as a separate step, regardless of whether
can_drive is true or false, I’d define cannot_drive as you have: to
always be not can_drive.

Have a think about how you’d do that - your code is very close.

1 Like

It’s REALLY loosely worded, but yeah, I’d be thinking the same as you are. Which results in a weird set of variables at the end. But, if that’s what the instructor’s looking for, so be it.

1 Like

Thank you Cameron.
It’s the first time I post something. I will follow your suggestion next time

  1. Please edit your original post and post actual code in between code brackets so we can copy and paste it to run it.
  2. What development environment are you using? Is it Google Colab? Jupyter?
  3. What is the error you are getting? If no error what is the bad result you are getting?

I think there’s no error, you’re doing exactly what the instruction says, and your code is valid. It’s either the instruction is unclear, or their test code is faulty.

I’d just move on to the next question, if I were you.

Did you solve this? I’m running into the exact same issue with this problem. I’ve tried different logic, and just flat setting the variables to specific bools but it says it’s wrong no matter what I do. I’ve checked both the variables are showing up as bools. I am beyond frustrated. Please let me know if you found a solution.

1 Like

I don’t know what the answer is. I created three different stetups and they all said the same thing. I finaly copied the professor and it was still wrong.
can_drive = False
age = 20

is_age_valid = 18 <= age <= 25

if is_age_valid:
cannot_drive = not can_drive

print(can_drive)
print(cannot_drive)

Read Cameron’s answer from May 2024. I agree that the test question is loosely worded.

Instructions unclear. I now have a cold fusion generator.