6.3.5 Cmu Cs Academy -

# Function: calculate_area # Parameters: width (int or float), height (int or float) # Returns: area (int or float) def calculate_area(width, height): area = width * height return area Key : Use return , not print() . Returning sends the value back to the caller. Step 3: Call the function in main() or global scope def main(): rect_area = calculate_area(10, 5) # Now rect_area holds 50 Step 4: Use the returned value Often they ask you to display it:

Label(f"Area: rect_area", 200, 200, size=20) from cmu_graphics import * def calculate_area(width, height): return width * height 6.3.5 Cmu Cs Academy

def main(): w = 10 h = 5 area = calculate_area(w, h) Label(f'Area = area', 200, 200, size=24, bold=True) # Function: calculate_area # Parameters: width (int or