Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
Loading…
Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
Loading…
Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
PYTHON FUNCTIONS / CHAPTER 04 / Learn / LESSON 04
Fourth class. A large task is easier to read when you split it into small, clearly named functions.
def base(n):
return n * 2def bonus(n):
return n + 1def total(n):
return base(n) + bonus(n)Each function does one job. total assembles the parts. That makes fixing and checking calmer.
Common mistake: one huge function with everything inside; or copying the same formula in three places instead of a helper.
Learn: assemble the solution from small parts.
BATCH IDLE
›