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 trialJonathan Gorman
1,599 PointsCan someone explain the order of operation please?
So the code makes sense but I'm not wrapping my head around the order that things are happening. So when the code starts it jumps straight to the Try: ? Why is the "return math.ceil(total_due / number_of_people)" one of the first things written in the function but one of the last things to execute? Can someone explain this please?
1 Answer
KRIS NIKOLAISEN
54,971 PointsYou have import, a function, and a try ... except statement. Import executes first to make math
available to the rest of the code. The split_check
function doesn't execute until it is called. You could define any number of functions and this would be the case. The return statement ends the execution of a function and many times as in this case you'll see it as the last statement of the function.
So you could say the code jumps to the try. Here the third statement within the try calls split_check
which is when that function code executes. You could call a function any number of times - one of the reasons for creating a function in the first place - and each time the code within the function would execute. If and only if there is a value error will the code in the except execute. You could have any number of except clauses - each handling different types of errors. If no exceptions are raised the code in the else clause executes.