Problem:
if num < 3
print('The number is ' + num)
print(f'{num is less than three')
prin('thanks for playing!")Solution:
-
SyntaxError: invalid syntaxMissing
:afterif num < 3. -
IndentationError: unexpected indentprin('thanks for playing!")is one space too far to the right. -
SyntaxError: EOL while scanning string literalMismatched 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 definedThere is no value set for
num. Definenumand assign a number to it that will satisfy the condition in theifstatment -
TypeError: can only concatenate str (not "int") to strThe value of
numis an integer, which cannot be concatenated to a string. We need to convertnumto a string using thestr()function or by converting the string to an f-string. -
NameError: name 'prin' is not definedA '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!