Here is the question:
Given the following code:
temp = "5 degrees"
cel = 0
fahr = float(temp)
cel = (fahr - 32.0) * 5.0 / 9.0
print(cel)
Which line/lines should be surrounded by try
block?
1
3
3,4
4
None
The “correct answer” is set to none, but the code would throw a traceback error for line 3. it is trying to convert a string to a float that has letters in it.
Traceback (most recent call last):
File “main.py”, line 3, in
fahr = float(temp)
ValueError: could not convert string to float: ‘5 degrees’