Jyggalag
(Jyggalag)
January 26, 2022, 9:37am
1
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.
aroberge
(André Roberge)
January 26, 2022, 10:33am
2
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
Jyggalag
(Jyggalag)
January 26, 2022, 10:34am
3
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
cameron
(Cameron Simpson)
January 26, 2022, 11:10am
4
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
Jyggalag
(Jyggalag)
January 26, 2022, 11:12am
5
This is correct!
Thank you sir. Helped me a lot in my initial start to Python!