Variables Debugging#
Each of the following short code contains one or more bugs.
Please identify and correct these bugs.
Provide an explanation for your answer.
Question-1#
state = 'NY'
int(state)
Solution
string state
can not be converted to an integer.
Question-2#
991_number = 'emergency'
Solution
variable names can not start with a digit
Question-3#
float('HI')
Solution
string HI
can not be converted to a float.
Question-4#
A = 3
print(a + 5)
Solution
a
is not defined because capital A
is 3
Question-5#
True = 5
print(True)
Solution
Keywords can not be used as a variable names. True
is a keyword.
Question-6#
print(int('5.0'))
Solution
5.0
is not an integer
Question-7#
age = 25
print('I am'+age+'years old.')
Solution
I am
is a string andage
is an integer.‘+’ can not be used to concatenate numbers and strings
Question-8#
print = 25
print('Hello')
Solution
In the first line, print becomes a variable, and its value is 25, so it loses its function property.