Skip to content

Commit a45b113

Browse files
committed
post TR1 commit
1 parent 91b9c1e commit a45b113

12 files changed

+280
-76
lines changed

marimo-notebook/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ You should create a new folder named marimo on your computer and place each of t
44

55
Your download bundle contains the following files:
66

7+
hypotenuse_calculator.py - This file contains the original hypotenuse_calculator code
78
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.
89
hypotenuse_calculator_duplicate_variable.py - This file shows the effect of re-defining a variable. This file produces an error.
910
hypotenuse_calculator_after_update.py - This file contains the code after the `adjacent` variable was updated to `10`. This file runs cleanly.
@@ -17,5 +18,7 @@ packages.py - This file contains the code used to demonstrate sandboxing.
1718
quadratic.py - This file contains the marimo notebook version of the quadratic formula example.
1819
equation.py - This file contains the Python script version of quadratic.py.
1920

21+
simultaneous_equations.py - This file contains the code used to demonstrate marimo's UI elements.
22+
simultaneous_equations_ui.py - This file contains a possible solution to the challenge skills test.
2023

2124
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.

marimo-notebook/break_even_analysis_UI_elements.py

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,37 @@
44
app = marimo.App(width="medium")
55

66

7-
@app.cell
8-
def _():
9-
import marimo as mo
10-
11-
return (mo,)
7+
app._unparsable_cell(
8+
r"""
9+
oimport marimo as mo
10+
""",
11+
name="_",
12+
)
1213

1314

1415
@app.cell
1516
def _(
16-
drop_color_costs,
17-
drop_quantity,
18-
rd_fixed_cost,
19-
sl_cost_price,
20-
text_selling_price,
17+
ui_color_costs,
18+
ui_fixed_cost,
19+
ui_quantity,
20+
ui_selling_price,
21+
ui_unit_cost,
2122
):
2223
import matplotlib.pyplot as plt
2324

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
25+
fixed_cost = int(ui_fixed_cost.value)
26+
unit_cost = ui_unit_cost.value
27+
selling_price = float(ui_selling_price.value)
28+
upper_production_quantity = ui_quantity.value
2829

2930
break_even_quantity = fixed_cost / (selling_price - unit_cost)
3031
break_even_income = break_even_quantity * selling_price
3132

32-
units = [
33-
quantity * 1000 for quantity in range(upper_production_quantity + 1)
34-
]
33+
units = range(0, upper_production_quantity + 1, 1000)
3534
unit_costs = [(unit * unit_cost) + fixed_cost for unit in units]
3635
sales_income = [unit * selling_price for unit in units]
3736

38-
plt.plot(units, unit_costs, marker="o", color=drop_color_costs.value)
37+
plt.plot(units, unit_costs, marker="o", color=ui_color_costs.value)
3938
plt.plot(units, sales_income, marker="x")
4039

4140
plt.xlabel("Units Produced")
@@ -73,41 +72,41 @@ def _(
7372
@app.cell
7473
def _(mo):
7574
options = ["40000", "50000"]
76-
rd_fixed_cost = mo.ui.radio(options=options, value="50000")
75+
ui_fixed_cost = mo.ui.radio(options=options, value="50000")
7776

78-
sl_cost_price = mo.ui.slider(start=2, stop=5, step=1)
77+
ui_unit_cost = mo.ui.slider(start=2, stop=5, step=1)
7978

80-
text_selling_price = mo.ui.text(value="10")
79+
ui_selling_price = mo.ui.text(value="10")
8180

82-
drop_quantity = mo.ui.dropdown(
83-
options={"10000": 10, "12000": 12, "15000": 15}, value="10000"
81+
ui_quantity = mo.ui.dropdown(
82+
options={"10000": 10000, "12000": 12000, "15000": 15000}, value="10000"
8483
)
8584

86-
sw_disply_break_even = mo.ui.switch()
85+
ui_disply_break_even = mo.ui.switch()
8786

88-
drop_color_costs = mo.ui.dropdown(
87+
ui_color_costs = mo.ui.dropdown(
8988
options={"Red": "red", "Green": "green", "Blue": "blue"}, value="Red"
9089
)
9190

9291
mo.md(
9392
f"""
94-
Select Fixed Costs: {rd_fixed_cost}
93+
Select Fixed Costs: {ui_fixed_cost}
9594
96-
Select Unit Cost Price: {sl_cost_price}
95+
Select Unit Cost Price: {ui_unit_cost}
9796
98-
Enter Selling Price: {text_selling_price}
97+
Enter Selling Price: {ui_selling_price}
9998
100-
Select a Maximum Quantity: {drop_quantity}
99+
Select a Maximum Production Quantity: {ui_quantity}
101100
"""
102101
)
103102
return (
104-
drop_color_costs,
105-
drop_quantity,
106103
options,
107-
rd_fixed_cost,
108-
sl_cost_price,
109-
sw_disply_break_even,
110-
text_selling_price,
104+
ui_color_costs,
105+
ui_disply_break_even,
106+
ui_fixed_cost,
107+
ui_quantity,
108+
ui_selling_price,
109+
ui_unit_cost,
111110
)
112111

113112

marimo-notebook/break_even_analysis_chart_code.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ def _():
1111
fixed_cost = 50000
1212
unit_cost = 2
1313
selling_price = 10
14-
unit_range = 10
14+
upper_production_quantity = 10000
1515

1616
break_even_quantity = fixed_cost / (selling_price - unit_cost)
1717
break_even_income = fixed_cost + break_even_quantity * unit_cost
1818

19-
units = [x * 1000 for x in range(unit_range)]
19+
units = range(0, upper_production_quantity + 1, 1000)
2020
unit_costs = [(x * unit_cost) + fixed_cost for x in units]
2121
sales_income = [unit * selling_price for unit in units]
2222

@@ -50,7 +50,7 @@ def _():
5050
selling_price,
5151
unit_cost,
5252
unit_costs,
53-
unit_range,
53+
upper_production_quantity,
5454
units,
5555
)
5656

marimo-notebook/break_even_analysis_solution.py

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -13,36 +13,36 @@ def _():
1313

1414
@app.cell
1515
def _(
16-
drop_plot_color,
17-
drop_quantity,
18-
rd_fixed_cost,
19-
sl_cost_price,
20-
sw_break_even,
21-
text_selling_price,
16+
ui_break_even,
17+
ui_fixed_cost,
18+
ui_plot_color,
19+
ui_quantity,
20+
ui_selling_price,
21+
ui_unit_cost,
2222
):
2323
import matplotlib.pyplot as plt
2424

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
25+
fixed_cost = int(ui_fixed_cost.value)
26+
unit_cost = ui_unit_cost.value
27+
selling_price = float(ui_selling_price.value)
28+
upper_production_quantity = ui_quantity.value
2929

3030
break_even_quantity = fixed_cost / (selling_price - unit_cost)
3131
break_even_income = break_even_quantity * selling_price
3232

33-
units = [quantity * 1000 for quantity in range(unit_range + 1)]
33+
units = range(0, upper_production_quantity + 1, 1000)
3434
total_costs = [(unit * unit_cost) + fixed_cost for unit in units]
3535
sales_income = [unit * selling_price for unit in units]
3636

37-
plt.plot(units, total_costs, marker="o", color=drop_plot_color.value)
37+
plt.plot(units, total_costs, marker="o", color=ui_plot_color.value)
3838
plt.plot(units, sales_income, marker="x")
3939

4040
plt.xlabel("Units Produced")
4141
plt.ylabel("($)")
4242
plt.legend(["Total Costs", "Total Income"])
4343
plt.title("Break-Even Analysis")
4444

45-
if sw_break_even.value:
45+
if ui_break_even.value:
4646
plt.vlines(
4747
break_even_quantity,
4848
ymin=100,
@@ -67,53 +67,53 @@ def _(
6767
selling_price,
6868
total_costs,
6969
unit_cost,
70-
unit_range,
7170
units,
71+
upper_production_quantity,
7272
)
7373

7474

7575
@app.cell
7676
def _(mo):
7777
options = ["40000", "50000"]
78-
rd_fixed_cost = mo.ui.radio(options=options, value="50000")
78+
ui_fixed_cost = mo.ui.radio(options=options, value="50000")
7979

80-
sl_cost_price = mo.ui.slider(start=2, stop=5, step=1)
80+
ui_unit_cost = mo.ui.slider(start=2, stop=5, step=1)
8181

82-
text_selling_price = mo.ui.text(value="10")
82+
ui_selling_price = mo.ui.text(value="10")
8383

84-
drop_quantity = mo.ui.dropdown(
85-
options={"10000": 10, "12000": 12, "15000": 15}, value="10000"
84+
ui_quantity = mo.ui.dropdown(
85+
options={"10000": 10000, "12000": 12000, "15000": 15000}, value="10000"
8686
)
8787

88-
sw_break_even = mo.ui.switch()
88+
ui_break_even = mo.ui.switch()
8989

90-
drop_plot_color = mo.ui.dropdown(
90+
ui_plot_color = mo.ui.dropdown(
9191
options={"Red": "red", "Green": "green", "Blue": "blue"}, value="Red"
9292
)
9393

9494
mo.md(
9595
f"""
96-
Select Fixed Costs: {rd_fixed_cost}
96+
Select Fixed Costs: {ui_fixed_cost}
9797
98-
Select Unit Cost Price: {sl_cost_price}
98+
Select Unit Cost Price: {ui_unit_cost}
9999
100-
Enter Selling Price: {text_selling_price}
100+
Enter Selling Price: {ui_selling_price}
101101
102-
Select a Maximum Quantity: {drop_quantity}
102+
Select a Maximum Quantity: {ui_quantity}
103103
104-
Display Break-Even Data: {sw_break_even}
104+
Display Break-Even Data: {ui_break_even}
105105
106-
Select Total Costs Plot Color: {drop_plot_color}
106+
Select Total Costs Plot Color: {ui_plot_color}
107107
"""
108108
)
109109
return (
110-
drop_plot_color,
111-
drop_quantity,
112110
options,
113-
rd_fixed_cost,
114-
sl_cost_price,
115-
sw_break_even,
116-
text_selling_price,
111+
ui_break_even,
112+
ui_fixed_cost,
113+
ui_plot_color,
114+
ui_quantity,
115+
ui_selling_price,
116+
ui_unit_cost,
117117
)
118118

119119

marimo-notebook/hidden_state.ipynb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"outputs": [],
1919
"source": [
2020
"def calculate_hypotenuse(opposite, adjacent):\n",
21-
" return math.sqrt(math.pow(opposite, 2) + math.pow(adjacent, 2))"
21+
" return math.sqrt(opposite**2 + adjacent**2)"
2222
]
2323
},
2424
{
@@ -131,6 +131,14 @@
131131
"metadata": {},
132132
"outputs": [],
133133
"source": []
134+
},
135+
{
136+
"cell_type": "code",
137+
"execution_count": null,
138+
"id": "75cbba4e-deeb-42dc-b3da-c69f4e71eb1a",
139+
"metadata": {},
140+
"outputs": [],
141+
"source": []
134142
}
135143
],
136144
"metadata": {
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import marimo
2+
3+
__generated_with = "0.11.0"
4+
app = marimo.App(width="medium")
5+
6+
7+
@app.cell
8+
def _(math):
9+
def calculate_hypotenuse(opposite, adjacent):
10+
return math.sqrt(opposite**2 + adjacent**2)
11+
12+
return (calculate_hypotenuse,)
13+
14+
15+
@app.cell
16+
def _():
17+
opposite = 3
18+
return (opposite,)
19+
20+
21+
@app.cell
22+
def _():
23+
adjacent = 4
24+
return (adjacent,)
25+
26+
27+
@app.cell
28+
def _(adjacent, calculate_hypotenuse, opposite):
29+
calculate_hypotenuse(opposite, adjacent)
30+
return
31+
32+
33+
@app.cell
34+
def _():
35+
import math
36+
37+
return (math,)
38+
39+
40+
if __name__ == "__main__":
41+
app.run()

marimo-notebook/hypotenuse_calculator_after_deletion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
@app.cell
88
def _(math):
99
def calculate_hypotenuse(opposite, adjacent):
10-
return math.sqrt(math.pow(opposite, 2) + math.pow(adjacent, 2))
10+
return math.sqrt(opposite**2 + adjacent**2)
1111

1212
return (calculate_hypotenuse,)
1313

marimo-notebook/hypotenuse_calculator_after_update.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
@app.cell
88
def _(math):
99
def calculate_hypotenuse(opposite, adjacent):
10-
return math.sqrt(math.pow(opposite, 2) + math.pow(adjacent, 2))
10+
return return math.sqrt(opposite**2 + adjacent**2)
1111

1212
return (calculate_hypotenuse,)
1313

marimo-notebook/hypotenuse_calculator_before_update.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
@app.cell
88
def _(math):
99
def calculate_hypotenuse(opposite, adjacent):
10-
return math.sqrt(math.pow(opposite, 2) + math.pow(adjacent, 2))
10+
return return math.sqrt(opposite**2 + adjacent**2)
1111

1212
return (calculate_hypotenuse,)
1313

marimo-notebook/hypotenuse_calculator_duplicate_variable.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
@app.cell
88
def _(math):
99
def calculate_hypotenuse(opposite, adjacent):
10-
return math.sqrt(math.pow(opposite, 2) + math.pow(adjacent, 2))
10+
return return math.sqrt(opposite**2 + adjacent**2)
1111

1212
return (calculate_hypotenuse,)
1313

0 commit comments

Comments
 (0)