Python Functions
💡
Exercise 32

Stonks 15 XP Medium

Ctrl+Enter Run Ctrl+S Save

Let's use functions to calculate stock market gains! 📈

Profit = Selling Price - Buying Price

Return % = (Profit / Buying Price) × 100

📋 Instructions
Create a function `stock_profit(buy_price, sell_price, shares)` that: 1. Calculates total profit: `(sell_price - buy_price) * shares` 2. Calculates return percentage: `((sell_price - buy_price) / buy_price) * 100` 3. Prints both values Test: ```python stock_profit(100, 150, 10) ``` Expected output: ``` Profit: $500 Return: 50.0% ```
profit = (sell_price - buy_price) * shares. Return pct = ((sell_price - buy_price) / buy_price) * 100.
🧪 Test Cases
Input
Run your code
Expected
Profit: $500 Return: 50.0%
Expected program output
main.py
Hi! I'm Rex 👋
Output
Ready. Press ▶ Run or Ctrl+Enter.