Help me fix my super simple Python code please

Dear all,

I am ABSOLUTELY new to Python and am just starting to try and learn it. I made this really simple code, but for some reason it does not work/run? Can somebody please help me? Would be greatly appreciated!

Actual code:

car = red

if car == red
print(“the car is green!”)

if car == green
print(“the car is green!”)

number = 5

while number >= 0
number += 1
print(“number”)

apparently the error is when I type if car == green and then indent a print statement, I tried typing if car = green as well, but it did not fix the issue.

When you have a statement which is followed by an indented code block, such as an if statement, you must include a colon (:) at the end; thus:

if car == red:
    print("The car is red!")
1 Like

Ah yes of course, I forgot about that part!

Thank you very much sir!

Should I type Car == “red” or Car = red for future reference?

Kind regards,
Jyggalag

Looking at your code, probably "red". "red" is a string containing
the letters red. The expression:

car == "red"

compares the value of the variable car with the string "red". The
expression:

car == red

compares the value of the variable car with the value of the variable
red. Which you haven’t yet defined, so that won’t work.

I expect you want the string.

Cheers,
Cameron Simpson cs@cskk.id.au

1 Like

This is correct!

Thank you sir. :slight_smile: Helped me a lot in my initial start to Python!