Handing an Answer Back ๐ฏ
So far your functions print things. But printing just puts words on the screen โ your program can't use them for anything.
return hands a value back to whoever called the function, so you can
store it, print it, or do more math with it:
def double(number):
return number * 2
result = double(7)
print(result) # โ 14
print(double(50)) # โ 100
print(double(3) + 1) # โ 7
See the difference?
print= show it on screen and forget itreturn= hand it back so your program can keep using it
One more thing: return ends the function immediately. Anything
written after it never runs.
Your mission
- Build
double(number)that returns the number times 2 (no print inside!) - Build
area(width, height)that returns width times height - Print
double(12) - Store
area(5, 3)in a variable, then print a sentence about it
Your code
Press โถ Run to see what your code does!