📝 Assignment: Optimize Business Profit Using Python
📘 Objective
You will use Python and [Link] to:
Build a simple profit function for a product.
Understand how price affects sales.
Find the best price that gives maximum profit.
📂 Instructions
1. Understand the Problem
A business sells a product. When the price increases, fewer people buy
it. Your job is to:
o Create a profit function.
o Use [Link] to find the price that gives the
highest profit.
2. Given Information
o If price increases, sales drop:
quantity = 1000 - 10 × price
o Cost per item = $20
3. Profit Formula
Profit=(price×quantity)−(cost×quantity)\text{Profit} = (\text{price} \times \
text{quantity}) - (\text{cost} \times \text{quantity})Profit=(price×quantity)
−(cost×quantity)
✅ What You Need to Do
Task 1: Write a Python function profit(x) where x is a list with one value
(price). The function should:
Calculate quantity based on price.
Calculate and return the negative of profit (because we will use
minimize()).
Task 2: Use [Link]() to find the price that gives maximum
profit.
Task 3: Print:
The best price.
The maximum profit.
📊 Questions to Answer
Write short answers after your code.
1. What is the best price according to your result?
2. What is the quantity sold at this price?
3. What is the maximum profit?
4. If the cost per item increased to $25, what would happen to the best
price?
5. What does this assignment teach you about how price affects profit?
🧪 Bonus Task (Optional)
Try changing the quantity formula to:
python
CopyEdit
quantity = 1500 - 15 * price
See how the result changes. Does the best price go up or down?
Great! Here are 4 more easy Python + SciPy assignments for your
students, each based on real-world or simple science problems.
🧪 Assignment 2: Interpolation of Missing Weather Data
🎯 Objective:
Use [Link] to fill in missing temperature values.
📂 Instructions:
1. You are given temperature data for a few days.
2. Some days have missing data (represented as NaN or missing values).
3. Use interpolation to estimate the missing values.
📝 Tasks:
Create a list of days [1, 2, 3, 4, 6, 7, 9]
Create matching temperature values like [30, 32, 33, 31, 35, 34, 36]
Use interp1d() to estimate temperatures for missing days (day 5 and
day 8)
Plot the original and interpolated data using matplotlib.
❓ Questions:
1. What type of interpolation did you use? (linear, cubic?)
2. What are the interpolated temperatures for day 5 and day 8?
3. Why is interpolation useful in real-world weather datasets?
⏳ Assignment 3: Simulate a Simple Pendulum
🎯 Objective:
Use SciPy to simulate the swinging of a pendulum over time.
📂 Instructions:
1. Use [Link] to solve the pendulum's equation.
2. Plot angle vs. time.
📝 Tasks:
Define the ODE for a simple pendulum:
θ′′(t)+gLsin(θ(t))=0\theta''(t) + \frac{g}{L} \sin(\theta(t)) = 0
Set initial conditions: θ = 0.2 rad, ω = 0 rad/s, g = 9.81, L = 1.0
Plot the result for time from 0 to 10 seconds.
❓ Questions:
1. What happens to the pendulum over time?
2. What does changing L (length) do to the motion?
3. What part of this simulation helps us understand physics better?
📈 Assignment 4: Population Growth Using ODE
🎯 Objective:
Model how a population grows over time using the logistic growth model.
📂 Instructions:
Use:
dPdt=rP(1−PK)\frac{dP}{dt} = rP\left(1 - \frac{P}{K}\right)
where:
P = population
r = growth rate
K = carrying capacity
📝 Tasks:
Write a function for the logistic equation
Use odeint to solve it over 20 years
Plot population vs. time
❓ Questions:
1. How fast does the population grow?
2. What happens when the population reaches the carrying capacity?
3. What happens if r is increased?
📉 Assignment 5: Butterworth Low-Pass Filter
🎯 Objective:
Use [Link] to filter noise from a signal.
📂 Instructions:
1. Generate a signal with two frequencies: 1 Hz and 50 Hz
2. Add noise
3. Apply a low-pass Butterworth filter to keep only the low frequency
📝 Tasks:
Use butter() to create the filter
Use filtfilt() to apply it
Plot before and after
❓ Questions:
1. What frequency did your filter allow through?
2. What does a low-pass filter do?
3. How can this be useful in real applications like sound or ECG?