Python Python Basics (2015) Number Game App Number Game Refinement

livia salgado
livia salgado
4,297 Points

at minute 1.24 Kenneth says So we want to safely make an int, because right now we're not doing that. What do you mean?

on the video at 1 minute 24 seconds Kenneth says safely make an int, i really don't know what that means, thanks!

1 Answer

Alex Koumparos
MOD
Alex Koumparos
Python Web Development Treehouse Moderator 32,453 Points

Hi Livia,

Whenever you do a type conversion from string to int there is a risk that the string value is something that can't be converted to a int (e.g., 'hello'). Without error handling code this would cause the program to crash. Because of the risk of crashing, this kind of type conversion is described as 'unsafe'.

By wrapping this unsafe operation in a try block which means we can handle the cases when an invalid value gets passed to the type conversion, we take away that crash risk and so make the 'unsafe' behaviour 'safe'.

Hope that clears it up.

Cheers

Alex