Need help for the following question

Please help me with the following question. Please give reason for the same.

Q) Given the following code:

1| temp = “5 degrees”
2| cel = 0
3| fahr = float(temp)
4| cel = (fahr - 32.0) * 5.0 / 9.0
5| print(cel)

which line/lines should be surrounded by “try” block?

What do you think might be the answer? We aren’t a homework service, so we won’t do the work for you, but we’re happy to help you work through it.

ok look, I know that 3rd line will come, But the answer is showing 3 and 4 and I don’t know why. If you don’t know the answer then don’t waste your PRECIOUS time answering this. you may utilize it in some other PRECIOUS, EXTREMELY IMPORTANT THING.

I know the answer. But we have a strict policy of not doing homework for users.

Why do you think the third line may fail? What will happen if it does? If you know what happens if the third line fails, then you’ll see why the fourth line also has a problem.

Adding to what @JeremyLT asked, what do you believe is the purpose of a try block in general when coding?

1 Like

4th line is dependent on 3rd Line so I don’t see a need to cover it up with a try/except block.

But that’s exactly why you need to do so. If the third line fails, is fahr defined?

Ohk Understood. Thank you so much.
Also I didn’t know the community guidelines and the fact that you are a Moderator.
So I thought you as a Random guy answering me rudely in the first post.
Will not repeat such things again. @JeremyLT

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.