A return value is the result a function sends back to the code that called it. Calling a function runs its code; storing the returned result in a variable lets you use it later. section 3.1.2 section 4.3.1
When working with return values:
- Pass arguments that match the function’s expected parameter types. section 3.1.2
- Assign the result to a variable when you need to use it later; otherwise, it can be lost. section 3.1.2
- Test different input categories, including negative, zero, and positive outcomes. section 3.3.1
Calculating money made
The function `money_made(10, 15, 17)` returns `20`. With a current price of 15, it returns `0`; with a current price of 15 after purchasing at 17, it returns `-20`. These cases show that a return value can represent profit, no change, or loss. section 3.3.1
return num_shares * (current_share_price - purchase_share_price)
This listing shows a return statement sending a calculated expression back to the caller. section 3.3.1
password = input("Enter a strong password: ")
while not is_strong_password(password): #1
password = input("Enter a strong password: ")
return password
This listing shows a function returning the password only after repeated input satisfies the strength check. section 3.3.3







