Problem:
if num < 3
print('The number is ' + num)
print(f'{num is less than three')
prin('thanks for playing!")
Solution:
-
SyntaxError: invalid syntax
Missing
:
afterif num < 3
. -
IndentationError: unexpected indent
prin('thanks for playing!")
is one space too far to the right. -
SyntaxError: EOL while scanning string literal
Mismatched quotes in
prin('thanks for playing!")
. String starts with a single quote and ends with a double -
SyntaxError: f-string: expecting '}'
The f-string in the line:
print(f'{num is less than three')
is missing a closing curly bracket after the variable num -
NameError: name 'num' is not defined
There is no value set for
num
. Definenum
and assign a number to it that will satisfy the condition in theif
statment -
TypeError: can only concatenate str (not "int") to str
The value of
num
is an integer, which cannot be concatenated to a string. We need to convertnum
to a string using thestr()
function or by converting the string to an f-string. -
NameError: name 'prin' is not defined
A 't' is missing from the end of
print()
, preventing the function from being found.
Final code:
num = 1
if num < 3:
# using an f-string
print(f'The number is {num}')
# using str()
# print('The number is ' + str(num))
print(f'{num} is less than three')
print('thanks for playing!')
Final output:
The number is 1
1 is less than three
thanks for playing!