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

Jonathan Alvarez
Jonathan Alvarez
549 Points

why is the answer C for the print for the first question after the exceptions video?

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

Why would it only print ADF and not ACDFE?

1 Answer

Rohald van Merode
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Rohald van Merode
Treehouse Staff

Hi Jonathan Alvarez 👋

When this code block runs it will print "A" right at the start. Then in the try block, when trying to run "test" + 5 a TypeError occurs so "D" will be printed, this concludes the try block and the final print will print the "F"

There's no ValueError happening in this code so "C" will not be printed. The else block will only run if there ware no exceptions, "E" will therefor not be printed either 🙂

Hope this clears things up! 😃