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 All Together Now Cleaner Code Through Refactoring

Lukas Johmann
Lukas Johmann
911 Points

I got the code to calculate Service Charge without making a function

Other than good practice for clean code, and readability, I don't see any purposes right now for making an extra function for service charge. I was able to add the Service charge into the code with a lot less work and seemingly the same end result.

amount_due = (TICKET_PRICE * num_tickets) + SERVICE_CHARGE

Can someone explain to me what this calculate_price function can achieve or allow us to do with our code?

I would appreciate your responses :) Thanks in advance

1 Answer

Like you said, defining this function isn't necessary. Craig basically mentions this, as well. Usually the reason for creating functions is to avoid repeating code, and in this video that's not case.

All in all, for the scope of the video, it isn't needed, but the only point is for refactoring. Cleaner code goes a very long way when projects get larger, so sometimes its best to think ahead in the beginning.