Skip to content

Commit 91b9c1e

Browse files
committed
Initial Commit
1 parent d2f0c94 commit 91b9c1e

12 files changed

Lines changed: 776 additions & 0 deletions

marimo-notebook/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The materials contained in this download are designed to complement the RealPython tutorial [Marimo: A Reactive, Reproducible Notebook](https://realpython.com/marimo-notebook-reactive-reproducible/).
2+
3+
You should create a new folder named marimo on your computer and place each of these files inside it. You may also consider creating a [Python virtual environment](https://realpython.com/python-virtual-environments-a-primer/) within this folder.
4+
5+
Your download bundle contains the following files:
6+
7+
hypotenuse_calculator_before_update.py - This file contains the code before any updating is attempted. The code has been deliberately placed out of order, however it runs cleanly.
8+
hypotenuse_calculator_duplicate_variable.py - This file shows the effect of re-defining a variable. This file produces an error.
9+
hypotenuse_calculator_after_update.py - This file contains the code after the `adjacent` variable was updated to `10`. This file runs cleanly.
10+
hypotenuse_calculator_after_deletion.py - This file contains the code after the `opposite variable` was deleted. This file produces an error.
11+
12+
break_even_analysis_chart_code.py - This file contains the basic chart code. It will produce a break-even analysis for a fixed set of input data.
13+
break_even_analysis_UI_elements.py - This file contains includes the four UI interface elements to allow the plot to be adjusted.
14+
break_even_analysis_solution.py - This file contains a possible solution to the skills test.
15+
16+
packages.py - This file contains the code used to demonstrate sandboxing.
17+
quadratic.py - This file contains the marimo notebook version of the quadratic formula example.
18+
equation.py - This file contains the Python script version of quadratic.py.
19+
20+
21+
hidden_state.ipynb - This file contains a Jupyter Notebook that can be used as a starting point for the investigation of its problems. You should adjust it as instructed in the tutorial.
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
import marimo
2+
3+
__generated_with = "0.11.0"
4+
app = marimo.App(width="medium")
5+
6+
7+
@app.cell
8+
def _():
9+
import marimo as mo
10+
11+
return (mo,)
12+
13+
14+
@app.cell
15+
def _(
16+
drop_color_costs,
17+
drop_quantity,
18+
rd_fixed_cost,
19+
sl_cost_price,
20+
text_selling_price,
21+
):
22+
import matplotlib.pyplot as plt
23+
24+
fixed_cost = int(rd_fixed_cost.value)
25+
unit_cost = sl_cost_price.value
26+
selling_price = float(text_selling_price.value)
27+
upper_production_quantity = drop_quantity.value
28+
29+
break_even_quantity = fixed_cost / (selling_price - unit_cost)
30+
break_even_income = break_even_quantity * selling_price
31+
32+
units = [
33+
quantity * 1000 for quantity in range(upper_production_quantity + 1)
34+
]
35+
unit_costs = [(unit * unit_cost) + fixed_cost for unit in units]
36+
sales_income = [unit * selling_price for unit in units]
37+
38+
plt.plot(units, unit_costs, marker="o", color=drop_color_costs.value)
39+
plt.plot(units, sales_income, marker="x")
40+
41+
plt.xlabel("Units Produced")
42+
plt.ylabel("($)")
43+
plt.legend(["Total Costs", "Total Income"])
44+
plt.title("Break-Even Analysis")
45+
46+
plt.vlines(
47+
break_even_quantity,
48+
ymin=0,
49+
ymax=break_even_income,
50+
linestyles="dashed",
51+
)
52+
plt.text(
53+
x=break_even_quantity + 100,
54+
y=int(break_even_income / 2),
55+
s=int(break_even_quantity),
56+
)
57+
plt.grid()
58+
plt.show()
59+
return (
60+
break_even_income,
61+
break_even_quantity,
62+
fixed_cost,
63+
plt,
64+
sales_income,
65+
selling_price,
66+
unit_cost,
67+
unit_costs,
68+
units,
69+
upper_production_quantity,
70+
)
71+
72+
73+
@app.cell
74+
def _(mo):
75+
options = ["40000", "50000"]
76+
rd_fixed_cost = mo.ui.radio(options=options, value="50000")
77+
78+
sl_cost_price = mo.ui.slider(start=2, stop=5, step=1)
79+
80+
text_selling_price = mo.ui.text(value="10")
81+
82+
drop_quantity = mo.ui.dropdown(
83+
options={"10000": 10, "12000": 12, "15000": 15}, value="10000"
84+
)
85+
86+
sw_disply_break_even = mo.ui.switch()
87+
88+
drop_color_costs = mo.ui.dropdown(
89+
options={"Red": "red", "Green": "green", "Blue": "blue"}, value="Red"
90+
)
91+
92+
mo.md(
93+
f"""
94+
Select Fixed Costs: {rd_fixed_cost}
95+
96+
Select Unit Cost Price: {sl_cost_price}
97+
98+
Enter Selling Price: {text_selling_price}
99+
100+
Select a Maximum Quantity: {drop_quantity}
101+
"""
102+
)
103+
return (
104+
drop_color_costs,
105+
drop_quantity,
106+
options,
107+
rd_fixed_cost,
108+
sl_cost_price,
109+
sw_disply_break_even,
110+
text_selling_price,
111+
)
112+
113+
114+
if __name__ == "__main__":
115+
app.run()
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import marimo
2+
3+
__generated_with = "0.10.14"
4+
app = marimo.App(width="medium")
5+
6+
7+
@app.cell
8+
def _():
9+
import matplotlib.pyplot as plt
10+
11+
fixed_cost = 50000
12+
unit_cost = 2
13+
selling_price = 10
14+
unit_range = 10
15+
16+
break_even_quantity = fixed_cost / (selling_price - unit_cost)
17+
break_even_income = fixed_cost + break_even_quantity * unit_cost
18+
19+
units = [x * 1000 for x in range(unit_range)]
20+
unit_costs = [(x * unit_cost) + fixed_cost for x in units]
21+
sales_income = [unit * selling_price for unit in units]
22+
23+
plt.plot(units, unit_costs, marker="o")
24+
plt.plot(units, sales_income, marker="x")
25+
26+
plt.xlabel("Units Produced")
27+
plt.ylabel("($)")
28+
plt.legend(["Total Costs", "Total Income"])
29+
plt.title("Break-Even Analysis")
30+
31+
plt.vlines(
32+
break_even_quantity,
33+
ymin=0,
34+
ymax=break_even_income,
35+
linestyles="dashed",
36+
)
37+
plt.text(
38+
x=break_even_quantity + 100,
39+
y=int(break_even_income / 2),
40+
s=int(break_even_quantity),
41+
)
42+
plt.grid()
43+
plt.show()
44+
return (
45+
break_even_income,
46+
break_even_quantity,
47+
fixed_cost,
48+
plt,
49+
sales_income,
50+
selling_price,
51+
unit_cost,
52+
unit_costs,
53+
unit_range,
54+
units,
55+
)
56+
57+
58+
if __name__ == "__main__":
59+
app.run()
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
import marimo
2+
3+
__generated_with = "0.11.0"
4+
app = marimo.App(width="medium")
5+
6+
7+
@app.cell
8+
def _():
9+
import marimo as mo
10+
11+
return (mo,)
12+
13+
14+
@app.cell
15+
def _(
16+
drop_plot_color,
17+
drop_quantity,
18+
rd_fixed_cost,
19+
sl_cost_price,
20+
sw_break_even,
21+
text_selling_price,
22+
):
23+
import matplotlib.pyplot as plt
24+
25+
fixed_cost = int(rd_fixed_cost.value)
26+
unit_cost = sl_cost_price.value
27+
selling_price = float(text_selling_price.value)
28+
unit_range = drop_quantity.value
29+
30+
break_even_quantity = fixed_cost / (selling_price - unit_cost)
31+
break_even_income = break_even_quantity * selling_price
32+
33+
units = [quantity * 1000 for quantity in range(unit_range + 1)]
34+
total_costs = [(unit * unit_cost) + fixed_cost for unit in units]
35+
sales_income = [unit * selling_price for unit in units]
36+
37+
plt.plot(units, total_costs, marker="o", color=drop_plot_color.value)
38+
plt.plot(units, sales_income, marker="x")
39+
40+
plt.xlabel("Units Produced")
41+
plt.ylabel("($)")
42+
plt.legend(["Total Costs", "Total Income"])
43+
plt.title("Break-Even Analysis")
44+
45+
if sw_break_even.value:
46+
plt.vlines(
47+
break_even_quantity,
48+
ymin=100,
49+
ymax=break_even_income,
50+
linestyles="dashed",
51+
)
52+
53+
plt.text(
54+
x=break_even_quantity + 100,
55+
y=int(break_even_income / 2),
56+
s=int(break_even_quantity),
57+
)
58+
59+
plt.grid()
60+
plt.show()
61+
return (
62+
break_even_income,
63+
break_even_quantity,
64+
fixed_cost,
65+
plt,
66+
sales_income,
67+
selling_price,
68+
total_costs,
69+
unit_cost,
70+
unit_range,
71+
units,
72+
)
73+
74+
75+
@app.cell
76+
def _(mo):
77+
options = ["40000", "50000"]
78+
rd_fixed_cost = mo.ui.radio(options=options, value="50000")
79+
80+
sl_cost_price = mo.ui.slider(start=2, stop=5, step=1)
81+
82+
text_selling_price = mo.ui.text(value="10")
83+
84+
drop_quantity = mo.ui.dropdown(
85+
options={"10000": 10, "12000": 12, "15000": 15}, value="10000"
86+
)
87+
88+
sw_break_even = mo.ui.switch()
89+
90+
drop_plot_color = mo.ui.dropdown(
91+
options={"Red": "red", "Green": "green", "Blue": "blue"}, value="Red"
92+
)
93+
94+
mo.md(
95+
f"""
96+
Select Fixed Costs: {rd_fixed_cost}
97+
98+
Select Unit Cost Price: {sl_cost_price}
99+
100+
Enter Selling Price: {text_selling_price}
101+
102+
Select a Maximum Quantity: {drop_quantity}
103+
104+
Display Break-Even Data: {sw_break_even}
105+
106+
Select Total Costs Plot Color: {drop_plot_color}
107+
"""
108+
)
109+
return (
110+
drop_plot_color,
111+
drop_quantity,
112+
options,
113+
rd_fixed_cost,
114+
sl_cost_price,
115+
sw_break_even,
116+
text_selling_price,
117+
)
118+
119+
120+
if __name__ == "__main__":
121+
app.run()

marimo-notebook/equation.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
__generated_with = "0.11.0"
2+
3+
# %%
4+
import marimo as mo
5+
6+
# %%
7+
mo.md(
8+
r"""
9+
A quadratic equation is one of the form **$ax^2 + bx + c = 0$**, where a, b and c are constants, and a $\neq$ 0.
10+
11+
You can solve it using the *quadratic formula*:
12+
13+
$$x = \frac {-b \pm \sqrt{b^2 -4ac}} {2a}$$
14+
15+
For example, suppose you wanted to solve: **$2x^2 - 3x - 2 = 0$**
16+
"""
17+
)
18+
19+
# %%
20+
a = 2
21+
22+
# %%
23+
import math
24+
25+
# %%
26+
b = -3
27+
28+
# %%
29+
c = -2
30+
31+
# %%
32+
x1 = (-b + math.sqrt(b**2 - 4 * a * c)) / (2 * a)
33+
34+
# %%
35+
x2 = (-b - math.sqrt(b**2 - 4 * a * c)) / (2 * a)
36+
37+
# %%
38+
print(f"x = {x1} and {x2}.")

0 commit comments

Comments
 (0)