๐Ÿ PyQuest๐Ÿญ Function Factory ยท ๐ŸŽฏ Handing an Answer Back
โญ 0 XP๐Ÿ Python is waking upโ€ฆ

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 it
  • return = 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

  1. Build double(number) that returns the number times 2 (no print inside!)
  2. Build area(width, height) that returns width times height
  3. Print double(12)
  4. Store area(5, 3) in a variable, then print a sentence about it

Your code

Press โ–ถ Run to see what your code does!