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

How do you know what is supposed to print?

how do I know what should print without a function or variable with assigned values?

2 Answers

Steven Parker
Steven Parker
229,708 Points

All the print statements in the quiz examples put out literal strings (like this one: print("A")Β ), so no variables or functions or needed.

You task is to anticipate how the program flow will be redirected by the "try" and "except" statements, and determine which of the print statements will run. From there, you can determine what the output will be since each statement that runs will output a single letter.

rydavim
rydavim
18,813 Points

You'll want to walk through the code step by step for each question. Try going one line at a time and thinking about what would happen when it runs. This method should work for both questions, but here is an example below.

print("A") # does this print?
try:
    result = 5 + 5 # does this raise a ValueError or TypeError?
    print("B") # depending on whether an error is raised, does this run?
except ValueError:
    print("C") # did you trigger a ValueError?
except TypeError:
    print("D") # did you trigger a TypeError?
else:
    print("E") # if no errors were triggered, does this run?
print("F") # does this print?

Hopefully that gives you a place to start, but please let me know if you still have questions and we can walk through a solution. Happy coding!