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.