Python for Everybody - More Conditional Structures

Tell us what’s happening:

I think this is incorrect as we cannot change the string into int / float

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36 Edg/134.0.0.0

Challenge Information:

Python for Everybody - More Conditional Structures

If line 3 fails, is it possible to run line 4?

no it says, " fahr = float(temp)
ValueError: could not convert string to float: ‘5 degrees’ "
and throws error

You did not really answer my question.

No it doesn’t work buddy.

Ok buddy. Then if we only put a try block around line 3 and not line 4, then what would happen buddy?

? whats try block now ? i think the video “Python for everybody is running in old compiler thats why you guys are claiming the false answer as true” as in the previous quesiton there should be an optinos “error” so that i could pass through the quiz.

Just explain me how it works and i will leave this topic it seems like awkward for me as i nevery knew the reply was going to be from somebody so quickly

Buddy, the video was about try/except in Python. If you haven’t watched the video, you should do that before the quiz.

The answer the quiz wants is definitely true.

This is why the answer the quiz wants is the only correct one.

Buddy, i think you got me wrong. i tried to run the same code in my laptop compiler its showing the error as this is not my first python video i ahve watched multiple videos in youtube to learn i am just here if there is something i am missing about

Did you try using a try block only on line 3 and not line 4 with the given code? What happens buddy?

I don’t know what you are trying to say buddy, how about you explain clearly than pointing out did you do that did you not do that ?? huh ?

I did it this way as you said try using try block at line 3

temp = "5 degrees"
cel = 0
try:
    fahr = float(temp)
    cel = (fahr - 32.0) * 5.0 / 9.0
except:
    print(cel)

Now don’t point out a question for me please instead give me a proper solution

The quiz question does not say anything about putting other parts of the code into an except block buddy.

The quiz question says " Which line/lines should be surrounded by try block?" buddy.

The options are Line 1, Line 3, Lines 3 and 4, Line 4, or None.

Only one of these is correct buddy.

Like you said buddy, the code without a ‘try’ block has an error, so the last answer cannot be correct buddy.

Which of the remaining 4 answers do you think is the right one buddy? If you tell me which one you think is the correct answer buddy, it is easier for me to explain what that isn’t quite right buddy.

It looks like in your code you put lines 3 and 4 into a try block and line 5 into an except block.

I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

Thankyou for your explanation, actually this is my first hours in freecodecamp, i don’t know if you are an AI replying my text or real human so i am sorry for giving your precious time in trouble.

i rewatched the question and found rather saying what will be the answer it was saying where to keep the try block.
Previous question 3-5 were about outputs so i skipped them.

Thankyou for your help

1 Like