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

Python Python Basics Functions and Looping Exception Flow

Hello! I am very confused on how this code would run to output the letters. Can someone guide me step by step? Thanks!

Please guide me step by step as I am confused and stuck on this currently. Thanks!

It would be a little easier to help if you'd link the challenge you're stuck with.

It's also good practice to at least make an attempt at solving it, and then showing your work and show where you got stuck.

1 Answer

Assuming you mean this:

What would the output be of the following code?

print("A")
try:
    result = 5 + 5
    print("B")
except ValueError:
    print("C")
except TypeError:
    print("D")
else:
    print("E")
print("F")

It would go line by line.

First, it does `Print("A")

then it will

try:
  result = 5+5
  print("B")

since there are no errors in this code, this code will run successfully it will therefore execute print("B")

it will skip the except statements because neither of those errors have been encountered, so it will resume at the else: block

inside the else block there's print("E")

finally there's a print("F") command, that isn't in any of the blocks so that will always run.

hope that helps.

Thank you very much! Understand it thoroughly now.