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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Sohail Mirza](https://secure.gravatar.com/avatar/0b70940f69e505dc2918e7c43bedc749?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Sohail Mirza
Python Web Development Techdegree Student 5,158 PointsUnderstading the exception questions
Two questions are provided but i do understand the answers print("A") try: result = 5 + 5 print("B") except ValueError: print("C") except TypeError: print("D") else: print("E") print("F")
Answer ABEF
print("A") try: result = "test" + 5 print("B") except ValueError: print("C") except TypeError: print("D") else: print("E") print("F")
Answer answer ADF
Could someone please explain the results are what there are Thanks for advance
4 Answers
![Cooper Runstein](https://secure.gravatar.com/avatar/51849faf72df0677b8256b043707e287?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Cooper Runstein
11,850 PointsResult is what is being tried, if result isn't valid, it throws the exception. For example, if result is a string that is being cast to an integer, which won't work ('hello' can never be a number), it will cause one of the except cases to fire.
![Sohail Mirza](https://secure.gravatar.com/avatar/0b70940f69e505dc2918e7c43bedc749?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Sohail Mirza
Python Web Development Techdegree Student 5,158 PointsHi Cooper Thanks for the quick response Ok i understand it 30% better. i got the point of result is what being tried but what is the input for us to get result = 5 + 5. I am not sure if i worded that correctly if not could you run through the question step by step and explain what is happening at each stage
![Cooper Runstein](https://secure.gravatar.com/avatar/51849faf72df0677b8256b043707e287?s=60&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Cooper Runstein
11,850 PointsFor me, it made more sense when learning this to not use something constant, result = 5 + 5 will always be a valid expression, so it seems kinda silly to put it in a try/except block. Imagine result was an input instead:
try:
result = input('Give me a number')
my_new_number = int(result) + 5
except ValueError:
print('Whoops! That didn't work')
In this case, if result is a number, everything will work. If not, the exception will fire. In the case of their example, that result in a constant number, but if that constant isn't valid, the exception will still fire.
![Sohail Mirza](https://secure.gravatar.com/avatar/0b70940f69e505dc2918e7c43bedc749?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Sohail Mirza
Python Web Development Techdegree Student 5,158 PointsThe above makes clear sense and i can see the point of the valid expression. However if we are using your example for a second a valid input will be any number not a string. but back to the example print("A") try: result = 5 + 5 print("B") This part confuses me everything underneath this is fine. In others words in what scenario would it print B
![Cooper Runstein](https://secure.gravatar.com/avatar/51849faf72df0677b8256b043707e287?s=60&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Cooper Runstein
11,850 PointsIn that case, the exceptions will never fire, because result will always equal 10 and the program will always print B if it's in the try block. That's the problem with the challenge problem, you'd never need a try/except block for that scenario in real world code. If result is constant, every single time through the code the try block will pass. Typically try/except is used for situations where you're relying on external input that may or may not be valid.
![Sohail Mirza](https://secure.gravatar.com/avatar/0b70940f69e505dc2918e7c43bedc749?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Sohail Mirza
Python Web Development Techdegree Student 5,158 PointsOk got it..what a pointless question.. Thanks for you patients ..much appreciated