Learn
Functions
What Good are Functions?

You might have considered the situation where you would like to reuse a piece of code, just with a few different values. Instead of rewriting the whole code, it’s much cleaner to define a function, which can then be used repeatedly.

Instructions

1.

Check out the code in the editor. We’ve defined two functions: tax to calculate the tax on a bill, and tip to compute the tip.

See how much of the code you understand at first glance (we’ll explain it all soon). When you’re ready, click Run to continue.

Folder Icon

Take this course for free

Already have an account?