Try/except excercise

why the answer for this try/except question is line 3 and 4 instead of 3 only? i don’t understand what is dangerous in line 4

Welcome milfordyg.

Well, what do you think happens on line 4, if you only surround line 3 in a try block?

1 Like

if i get it correctly, when code fail in line 3, we should run an exception code right? there is no point to continue 4th line after a fail 3rd line, isn’t it?

thank you

i tried the code in vscode, i get why warp line 3 and 4 in try/except now. i got it wrong to think that exception code will terminate the program.
thank you sir, i should have try it myself before i ask here

I am glad you understand now. It is good that you asked for clarification before getting yourself confused.

So, yes. The try...except block is used to prevent the program from crashing.