Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
boi
14,242 PointsPython basics need HELP please
I have attached a link to my code, I have trouble understanding a few concepts. 1) Why can't we use ZeroDivisionError in the RAISE function, why only specifically ValueError? 2) there are 2 codes in the link provided below can you please check why my code2.py is not executing properly, and please guide me of what I have done wrong and how to avoid it. 3) In the code1.py when I run the code and give an input "a" it prints out,
(invalid literal for int() with base 10: 'a')
why is that? my code1.py seems fine to me
4) And lastly can you please clarify me with the concept why can't I use 2 except functions? and why ValueError specifically and not ZeroDivisionError
THANK YOU so much
https://w.trhou.se/kha40sbmuj (code files)
1 Answer
Steven Parker
243,266 PointsYou can raise a ZeroDivisionError if you want, but since the handler has no parameter the message passed will not be seen. (Only the one printed in the handler is shown).
Code2.py references a "division_error" on line 14, but nothing by that name has been defined (it's apparently left over from code1.py). The error parameter for that handler in code2.py is simply "err".
The "invalid literal" message is provided by the system and printed out on line 12 of code1.py. This is normal for a system-generated exception (instead of a "raise"d one).
And finally, you can indeed have multiple "except"s. What made you think otherwise?