import%20marimo%0A%0A__generated_with%20%3D%20%220.25.2%22%0Aapp%20%3D%20marimo.App(width%3D%22medium%22%2C%20app_title%3D%22Meet%20marimo%22)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_()%3A%0A%20%20%20%20import%20marimo%20as%20mo%0A%0A%20%20%20%20import%20course%0A%20%20%20%20from%20course%20import%20PATHS%2C%20check_cases%2C%20try_it%0A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%20Meet%20marimo%0A%0A%20%20%20%20Modules%201%20to%206%20were%20taught%20in%20Jupyter.%20This%20module%20takes%20their%20ideas%20into%20**marimo**%2C%20a%20notebook%20that%20runs%20differently%2C%20one%20module's%20idea%20at%20a%20time%2C%20and%20shows%20why%20the%20next%20course%2C%20*Arrays%20and%20DataFrames*%2C%20is%20taught%20in%20it.%20You%20opened%20this%20notebook%20with%20%60uv%20run%20marimo%20edit%2060_meet_marimo.py%60.%0A%0A%20%20%20%20%7C%20section%20%7C%20what%20you%20do%20%7C%0A%20%20%20%20%7C%3A--%7C%3A--%7C%0A%20%20%20%20%7C%201%20%C2%B7%20The%20same%20notebook%2C%20run%20differently%20%7C%20what%20marimo%20changes%20compared%20with%20Jupyter%2C%20and%20how%20to%20run%20a%20cell%20%7C%0A%20%20%20%20%7C%202%20%C2%B7%20Cells%20that%20rerun%20%7C%20module%202's%20names%20and%20values%2C%20kept%20up%20to%20date%20by%20the%20notebook%20itself%20%7C%0A%20%20%20%20%7C%203%20%C2%B7%20New%20values%2C%20not%20changed%20ones%20%7C%20module%203's%20habit%20of%20making%20a%20new%20list%2C%20which%20marimo%20relies%20on%20%7C%0A%20%20%20%20%7C%204%20%C2%B7%20A%20slider%20that%20reruns%20a%20loop%20%7C%20module%204's%20loop%2C%20run%20again%20whenever%20a%20control%20on%20the%20page%20moves%20%7C%0A%20%20%20%20%7C%205%20%C2%B7%20One%20function%2C%20many%20cells%20%7C%20module%205's%20functions%2C%20shared%20between%20cells%20%7C%0A%20%20%20%20%7C%206%20%C2%B7%20Pick%20a%20file%20%7C%20module%206's%20file%20reading%2C%20with%20the%20file%20chosen%20on%20the%20page%20%7C%0A%20%20%20%20%7C%207%20%C2%B7%20Putting%20it%20together%20%7C%20the%20rules%20of%20a%20marimo%20notebook%2C%20and%20an%20exercise%20%7C%0A%20%20%20%20%7C%208%20%C2%B7%20Notebooks%20as%20files%20%7C%20converting%20a%20Jupyter%20notebook%2C%20running%20a%20notebook%20as%20a%20script%2C%20and%20keeping%20it%20in%20git%20%7C%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%20PATHS%2C%20check_cases%2C%20course%2C%20mo%2C%20try_it%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(course)%3A%0A%20%20%20%20course.quizzes_at(%227.0%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%201%20%C2%B7%20The%20same%20notebook%2C%20run%20differently%0A%0A%20%20%20%20**Jupyter**%20runs%20a%20cell%20when%20you%20run%20it%2C%20in%20the%20order%20you%20choose.%20The%20kernel%20keeps%20every%20name%20you%20have%20set%2C%20so%20what%20the%20notebook%20holds%20depends%20on%20what%20you%20ran%2C%20how%20often%20and%20in%20which%20order%3A%20the%20hidden%20state%20of%20%6000_start.ipynb%60%2C%20section%202%2C%20which%20*Restart%20and%20Run%20All*%20clears.%0A%0A%20%20%20%20**marimo**%20reads%20which%20names%20each%20cell%20defines%20and%20which%20it%20uses%2C%20and%20runs%20cells%20in%20that%20order.%20When%20a%20cell%20changes%2C%20every%20cell%20that%20uses%20its%20names%20reruns%2C%20by%20itself.%20A%20marimo%20notebook%20therefore%20always%20shows%20what%20its%20cells%20say.%0A%0A%20%20%20%20It%20looks%20like%20a%20Jupyter%20notebook%2C%20cells%20and%20all.%20To%20run%20a%20cell%20you%20changed%2C%20press%20**Shift%20%2B%20Enter**%2C%20or%20click%20its%20%E2%96%B6%20button.%20Each%20section%20below%20takes%20one%20module's%20idea%20and%20shows%20what%20marimo%20does%20with%20it.%0A%0A%20%20%20%20%23%23%202%20%C2%B7%20Cells%20that%20rerun%0A%0A%20%20%20%20In%20module%202%20you%20gave%20values%20names%2C%20and%20in%20%6000_start.ipynb%60%20you%20saw%20a%20cell%20that%20counted%20up%20each%20time%20you%20ran%20it.%20Here%20are%20the%20same%20names%2C%20in%20marimo.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20visited%20%3D%200%0A%20%20%20%20return%20(visited%2C)%0A%0A%0A%40app.cell%0Adef%20_(visited)%3A%0A%20%20%20%20visited_now%20%3D%20visited%20%2B%201%0A%20%20%20%20visited_now%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20**Try%20it.**%20Change%20the%20cell%20above%20to%20%60visited%20%3D%205%60%20and%20run%20it.%20The%20cell%20below%20it%20reruns%20on%20its%20own%20and%20shows%20%606%60%3A%20you%20never%20run%20it%20yourself%2C%20and%20running%20it%20again%20changes%20nothing%2C%20because%20it%20always%20computes%20from%20the%20%60visited%60%20above.%0A%0A%20%20%20%20**What%20marimo%20refuses.**%20Add%20a%20new%20cell%20(the%20**%2B**%20under%20a%20cell)%20and%20type%20%60visited%20%3D%20visited%20%2B%201%60.%20marimo%20marks%20it%20with%20an%20error%3A%20**a%20name%20can%20be%20defined%20in%20one%20cell%20only**.%20That%20rule%20is%20what%20keeps%20the%20notebook%20honest%3A%20every%20name%20has%20exactly%20one%20cell%20that%20says%20what%20it%20is%2C%20so%20reading%20the%20notebook%20tells%20you%20what%20it%20holds.%20Delete%20that%20cell%20again.%0A%0A%20%20%20%20**The%20order%20on%20the%20page%20is%20free.**%20marimo%20runs%20cells%20in%20the%20order%20their%20names%20need%2C%20not%20the%20order%20they%20appear.%20The%20cell%20below%20uses%20%60members%60%2C%20which%20is%20defined%20in%20the%20cell%20after%20it%2C%20and%20still%20works.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(members)%3A%0A%20%20%20%20f%22%7Bmembers%7D%20members%2C%20%7B'a%20large'%20if%20members%20%3E%3D%206%20else%20'not%20a%20large'%7D%20household%22%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20members%20%3D%206%0A%20%20%20%20return%20(members%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20Change%20%60members%60%20to%20%603%60%20and%20watch%20the%20sentence%20above%20change.%0A%0A%20%20%20%20%23%23%203%20%C2%B7%20New%20values%2C%20not%20changed%20ones%0A%0A%20%20%20%20marimo%20reruns%20a%20cell%20when%20a%20name%20it%20uses%20gets%20a%20**new%20value**%3A%20when%20the%20cell%20that%20defines%20the%20name%20runs%20again.%20It%20does%20not%20watch%20for%20a%20list%20or%20a%20dictionary%20being%20**changed%20in%20place**%20(%60.append%60%2C%20%60.remove%60%2C%20%60record%5B%22members%22%5D%20%3D%206%60).%20A%20change%20like%20that%2C%20made%20in%20another%20cell%2C%20is%20invisible%20to%20marimo%2C%20and%20the%20cells%20that%20read%20the%20list%20are%20not%20rerun.%0A%0A%20%20%20%20The%20cells%20below%20grow%20a%20list%20of%20crops%20the%20way%20module%203%20recommends%3A%20each%20step%20makes%20a%20**new**%20list%20from%20the%20one%20before.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20planted%20%3D%20%5B%22Palay%22%2C%20%22Corn%22%5D%0A%20%20%20%20return%20(planted%2C)%0A%0A%0A%40app.cell%0Adef%20_(planted)%3A%0A%20%20%20%20this_season%20%3D%20planted%20%2B%20%5B%22Mango%22%5D%0A%20%20%20%20return%20(this_season%2C)%0A%0A%0A%40app.cell%0Adef%20_(this_season)%3A%0A%20%20%20%20f%22%7Blen(this_season)%7D%20crops%20this%20season%3A%20%7B'%2C%20'.join(sorted(this_season))%7D%22%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20**Try%20it.**%20Add%20%60%22Cassava%22%60%20to%20%60planted%60%20in%20the%20first%20of%20these%20cells%20and%20run%20it.%20Both%20cells%20below%20it%20rerun%20by%20themselves%3A%20the%20count%20says%204%2C%20and%20the%20list%20has%20Cassava.%0A%0A%20%20%20%20**What%20goes%20wrong%20with%20a%20change%20in%20place.**%20Add%20a%20new%20cell%20with%20%60planted.append(%22Coconut%22)%60%20and%20run%20it.%20marimo%20runs%20it%2C%20but%20no%20other%20cell%20reruns%2C%20because%20no%20name%20got%20a%20new%20value%3A%20the%20sentence%20above%20still%20says%204.%20Run%20the%20sentence's%20cell%20by%20hand%20and%20it%20says%205.%20The%20notebook%20now%20shows%20two%20different%20answers%20depending%20on%20which%20cells%20you%20ran%2C%20which%20is%20the%20hidden%20state%20marimo%20is%20built%20to%20avoid.%20Delete%20that%20cell%20again.%0A%0A%20%20%20%20The%20rule%20that%20keeps%20marimo%20honest%20is%20the%20same%20one%20that%20keeps%20a%20function%20from%20surprising%20its%20caller%3A%20**make%20a%20new%20value%20and%20give%20it%20a%20name**%2C%20rather%20than%20changing%20the%20old%20one.%20%60planted%20%2B%20%5B%22Mango%22%5D%60%2C%20%60sorted(...)%60%20and%20%60%7B**record%2C%20%22members%22%3A%206%7D%60%20all%20make%20new%20values.%0A%0A%20%20%20%20**A%20control%20instead%20of%20an%20edit.**%20marimo%20can%20also%20take%20values%20from%20a%20control%20on%20the%20page.%20Pick%20crops%20below%3A%20the%20cell%20after%20it%20reruns%20every%20time%20the%20choice%20changes%2C%20because%20the%20control's%20value%20is%20new%20each%20time.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20extra%20%3D%20mo.ui.multiselect(options%3D%5B%22Mango%22%2C%20%22Cassava%22%2C%20%22Coconut%22%2C%20%22Ampalaya%22%5D%2C%20value%3D%5B%22Mango%22%5D%2C%20label%3D%22Also%20planted%20this%20season%22)%0A%20%20%20%20extra%0A%20%20%20%20return%20(extra%2C)%0A%0A%0A%40app.cell%0Adef%20_(extra%2C%20planted)%3A%0A%20%20%20%20crops_now%20%3D%20planted%20%2B%20extra.value%0A%20%20%20%20f%22%7Blen(crops_now)%7D%20crops%3A%20%7B'%2C%20'.join(sorted(crops_now))%7D%22%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%204%20%C2%B7%20A%20slider%20that%20reruns%20a%20loop%0A%0A%20%20%20%20In%20module%204%2C%20to%20ask%20Exercise%204.3's%20question%20for%20another%20age%2C%20you%20changed%20the%20number%20in%20the%20cell%20and%20ran%20it%20again.%20In%20marimo%2C%20a%20**control**%20on%20the%20page%20can%20hold%20the%20number%20instead%3A%20move%20it%2C%20and%20every%20cell%20that%20uses%20its%20value%20reruns.%20The%20households%20are%20the%20course's%20records%2C%20read%20from%20the%20file%20as%20in%20module%206.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(PATHS)%3A%0A%20%20%20%20import%20csv%0A%0A%20%20%20%20with%20open(PATHS.data%20%2F%20%22households.csv%22%2C%20encoding%3D%22utf-8%22%2C%20newline%3D%22%22)%20as%20_f%3A%0A%20%20%20%20%20%20%20%20households%20%3D%20%5B%7B**row%2C%20%22members%22%3A%20int(row%5B%22members%22%5D)%2C%20%22head_age%22%3A%20int(row%5B%22head_age%22%5D)%7D%20for%20row%20in%20csv.DictReader(_f)%5D%0A%20%20%20%20return%20(households%2C)%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20age%20%3D%20mo.ui.slider(start%3D20%2C%20stop%3D85%2C%20step%3D1%2C%20value%3D60%2C%20label%3D%22Heads%20of%20household%20older%20than%22%2C%20show_value%3DTrue)%0A%20%20%20%20age%0A%20%20%20%20return%20(age%2C)%0A%0A%0A%40app.cell%0Adef%20_(age%2C%20households)%3A%0A%20%20%20%20older%20%3D%20%5B%5D%0A%20%20%20%20for%20household%20in%20households%3A%0A%20%20%20%20%20%20%20%20if%20household%5B%22head_age%22%5D%20%3E%20age.value%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20older.append(household%5B%22id%22%5D)%0A%20%20%20%20f%22%7Blen(older)%7D%20of%20%7Blen(households)%7D%20heads%20are%20older%20than%20%7Bage.value%7D%3A%20%7B'%2C%20'.join(older)%20or%20'none'%7D%22%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20**Try%20it.**%20Move%20the%20slider.%20The%20sentence%20changes%20as%20you%20move%20it%3A%20the%20cell%20with%20the%20loop%20reruns%20every%20time%2C%20because%20it%20uses%20%60age.value%60.%0A%0A%20%20%20%20The%20loop%20is%20the%20same%20%60for%60%20and%20%60if%60%20you%20wrote%20in%20Jupyter.%20What%20changes%20is%20who%20decides%20when%20it%20runs%3A%20you%2C%20by%20running%20a%20cell%2C%20in%20Jupyter%3B%20the%20notebook%20itself%2C%20whenever%20something%20it%20uses%20changes%2C%20in%20marimo.%0A%0A%20%20%20%20%23%23%205%20%C2%B7%20One%20function%2C%20many%20cells%0A%0A%20%20%20%20A%20function%20defined%20in%20one%20marimo%20cell%20can%20be%20used%20by%20any%20other%20cell%2C%20as%20a%20name%20like%20any%20other%2C%20as%20module%205's%20functions%20were.%20Change%20the%20function%2C%20and%20marimo%20reruns%20every%20cell%20that%20uses%20it%3A%20there%20is%20no%20stale%20result%20computed%20by%20the%20old%20version.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.function%0Adef%20yield_per_hectare(harvest_kg%2C%20area_sqm)%3A%0A%20%20%20%20%22%22%22A%20farm's%20yield%20in%20tonnes%20per%20hectare%2C%20rounded%20to%20two%20decimal%20places.%22%22%22%0A%20%20%20%20return%20round((harvest_kg%20%2F%201000)%20%2F%20(area_sqm%20%2F%2010000)%2C%202)%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20yield_per_hectare(2500%2C%205000)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20farms%20%3D%20%7B%22H001%22%3A%20(2500%2C%205000)%2C%20%22H002%22%3A%20(4300%2C%2012000)%2C%20%22H006%22%3A%20(1650%2C%203000)%2C%20%22H008%22%3A%20(6200%2C%208000)%7D%0A%20%20%20%20%7Bfarm%3A%20yield_per_hectare(harvest%2C%20area)%20for%20farm%2C%20(harvest%2C%20area)%20in%20farms.items()%7D%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20**Try%20it.**%20Change%20the%20function%20to%20round%20to%20one%20decimal%20place%2C%20and%20run%20its%20cell.%20Both%20cells%20below%20rerun%20on%20their%20own%20with%20the%20new%20rounding.%0A%0A%20%20%20%20In%20Jupyter%2C%20you%20would%20have%20to%20remember%20every%20cell%20that%20calls%20the%20function%20and%20run%20each%20again%3B%20miss%20one%2C%20and%20it%20shows%20a%20result%20from%20the%20old%20version.%20In%20marimo%2C%20the%20cells%20that%20use%20a%20name%20are%20always%20up%20to%20date%20with%20it.%0A%0A%20%20%20%20%23%23%206%20%C2%B7%20Pick%20a%20file%0A%0A%20%20%20%20A%20notebook%20that%20reads%20a%20file%20usually%20has%20the%20file's%20name%20typed%20into%20it%2C%20as%20module%206's%20did.%20In%20marimo%2C%20the%20file%20can%20come%20from%20a%20control%20on%20the%20page%20instead%3A%20choose%20one%2C%20and%20the%20cells%20that%20read%20it%20rerun%20with%20the%20new%20file.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(PATHS%2C%20mo)%3A%0A%20%20%20%20data_files%20%3D%20sorted(p.name%20for%20p%20in%20PATHS.data.iterdir()%20if%20p.is_file())%0A%20%20%20%20data_file%20%3D%20mo.ui.dropdown(options%3Ddata_files%2C%20value%3Ddata_files%5B0%5D%2C%20label%3D%22A%20file%20from%20the%20course's%20data%20folder%22)%0A%20%20%20%20data_file%0A%20%20%20%20return%20(data_file%2C)%0A%0A%0A%40app.cell%0Adef%20_(PATHS%2C%20data_file%2C%20mo)%3A%0A%20%20%20%20_lines%20%3D%20(PATHS.data%20%2F%20data_file.value).read_text(encoding%3D%22utf-8%22).splitlines()%0A%20%20%20%20mo.vstack(%5B%0A%20%20%20%20%20%20%20%20mo.md(f%22**%7Bdata_file.value%7D**%3A%20%7Blen(_lines)%7D%20lines.%20The%20first%20five%3A%22)%2C%0A%20%20%20%20%20%20%20%20mo.md(%22%60%60%60%5Cn%22%20%2B%20%22%5Cn%22.join(_lines%5B%3A5%5D)%20%2B%20%22%5Cn%60%60%60%22)%2C%0A%20%20%20%20%5D)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20**Try%20it.**%20Choose%20another%20file.%20The%20cell%20below%20the%20control%20reruns%3A%20it%20reads%20the%20file%20you%20chose%2C%20counts%20its%20lines%20and%20shows%20the%20first%20five.%0A%0A%20%20%20%20The%20reading%20is%20the%20same%20%60read_text%60%20you%20used%20in%20Jupyter.%20What%20marimo%20adds%20is%20that%20the%20choice%20is%20part%20of%20the%20notebook%3A%20someone%20opening%20it%20picks%20a%20file%20without%20touching%20the%20code.%0A%0A%20%20%20%20%23%23%207%20%C2%B7%20Putting%20it%20together%0A%0A%20%20%20%20Three%20rules%20follow%20from%20how%20marimo%20runs%20a%20notebook%2C%20and%20you%20have%20met%20each%20in%20this%20module%3A%0A%0A%20%20%20%20-%20**A%20name%20is%20defined%20in%20one%20cell%20only.**%20Two%20cells%20that%20both%20set%20%60total%60%20are%20refused%20(section%202).%0A%20%20%20%20-%20**Changes%20in%20place%20are%20not%20seen.**%20%60planted.append(...)%60%20in%20another%20cell%20does%20not%20rerun%20the%20cells%20that%20read%20%60planted%60%3B%20make%20a%20new%20list%20instead%20(section%203).%0A%20%20%20%20-%20**Order%20on%20the%20page%20is%20free.**%20A%20cell%20can%20use%20a%20name%20defined%20further%20down%20(section%202).%0A%0A%20%20%20%20And%20one%20thing%20Jupyter%20has%20no%20equivalent%20for%3A%20**controls**%20(%60mo.ui.slider%60%2C%20%60mo.ui.dropdown%60%20and%20many%20more)%20whose%20value%20cells%20can%20use%2C%20so%20that%20moving%20one%20reruns%20them%20(sections%203%2C%204%20and%206).%0A%0A%20%20%20%20Names%20that%20start%20with%20an%20underscore%20(%60_total%60)%20belong%20to%20their%20cell%20only%3A%20two%20cells%20can%20each%20have%20a%20%60_total%60%20without%20breaking%20the%20one-definition%20rule.%20The%20cell%20that%20reads%20a%20file%20in%20section%206%20uses%20%60_lines%60%20for%20that%20reason.%0A%0A%20%20%20%20The%20households%20of%20section%204%20again%2C%20with%20a%20control%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(households%2C%20mo)%3A%0A%20%20%20%20barangays%20%3D%20sorted(%7Bh%5B%22barangay%22%5D%20for%20h%20in%20households%7D)%0A%20%20%20%20barangay%20%3D%20mo.ui.dropdown(options%3D%5B%22all%22%2C%20*barangays%5D%2C%20value%3D%22all%22%2C%20label%3D%22Barangay%22)%0A%20%20%20%20barangay%0A%20%20%20%20return%20(barangay%2C)%0A%0A%0A%40app.cell%0Adef%20_(barangay%2C%20households%2C%20mo)%3A%0A%20%20%20%20shown%20%3D%20%5Bh%20for%20h%20in%20households%20if%20barangay.value%20in%20(%22all%22%2C%20h%5B%22barangay%22%5D)%5D%0A%20%20%20%20mo.md(f%22**%7Blen(shown)%7D%20households**%2C%20%7Bsum(h%5B'members'%5D%20for%20h%20in%20shown)%7D%20people%2C%20in%20%7Bbarangay.value%20if%20barangay.value%20!%3D%20'all'%20else%20'the%20three%20barangays'%7D.%22)%0A%20%20%20%20return%20(shown%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20Choose%20a%20barangay%3A%20the%20sentence%20reruns%2C%20and%20so%20does%20the%20exercise's%20**Try%20it**%20below%2C%20which%20uses%20the%20same%20households.%0A%0A%20%20%20%20%23%23%20Exercise%207.1%20%C2%B7%20Running%20totals%0A%0A%20%20%20%20A%20running%20total%20is%20the%20kind%20of%20thing%20that%20tempts%20a%20notebook%20into%20hidden%20state%3A%20in%20Jupyter%2C%20a%20cell%20with%20%60total%20%3D%20total%20%2B%20x%60%2C%20run%20again%20and%20again.%20In%20marimo%20that%20cell%20is%20refused%2C%20and%20the%20right%20shape%20is%20a%20function%20that%20gives%20back%20every%20total%20at%20once.%0A%0A%20%20%20%20Finish%20%60running_totals(values)%60%20so%20that%20it%20returns%20a%20list%20with%20the%20total%20so%20far%20after%20each%20value.%0A%0A%20%20%20%20%7C%20call%20%7C%20returns%20%7C%0A%20%20%20%20%7C%3A--%7C%3A--%7C%0A%20%20%20%20%7C%20%60running_totals(%5B5%2C%207%2C%202%5D)%60%20%7C%20%60%5B5%2C%2012%2C%2014%5D%60%20%7C%0A%20%20%20%20%7C%20%60running_totals(%5B%5D)%60%20%7C%20%60%5B%5D%60%20%7C%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.function%0Adef%20running_totals(values)%3A%0A%20%20%20%20%23%20Step%201%3A%20start%20a%20total%20at%200%20and%20an%20empty%20list%0A%20%20%20%20%23%20Step%202%3A%20for%20each%20value%2C%20add%20it%20to%20the%20total%20and%20append%20the%20total%20to%20the%20list%0A%20%20%20%20%23%20Step%203%3A%20return%20the%20list%0A%20%20%20%20raise%20NotImplementedError(%22Exercise%207.1%22)%20%20%23%20delete%20this%20line%20when%20your%20code%20is%20ready%0A%0A%0A%40app.cell%0Adef%20_(shown%2C%20try_it)%3A%0A%20%20%20%20try_it(running_totals%2C%20%5Bh%5B%22members%22%5D%20for%20h%20in%20shown%5D%5B%3A6%5D)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(check_cases)%3A%0A%20%20%20%20check_cases(%22Exercise%207.1%22%2C%20running_totals%2C%20%5B(f%22running_totals(%7Bv%7D)%22%2C%20(v%2C))%20for%20v%20in%20%5B%5B5%2C%207%2C%202%5D%2C%20%5B%5D%2C%20%5B1%5D%2C%20%5B3%2C%203%2C%203%2C%203%5D%2C%20%5B10%2C%20-4%2C%206%5D%5D%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20what%3D%22lists%22%2C%20hint%3D%22Append%20the%20total%20after%20adding%20each%20value.%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.accordion(%7B%22If%20the%20check%20is%20red%3A%20common%20causes%20for%20Exercise%207.1%22%3A%20mo.md(r%22%22%22%0A%20%20%20%20-%20**Only%20the%20grand%20total**%3A%20the%20function%20returns%20the%20total%2C%20not%20the%20list%20of%20totals.%0A%20%20%20%20-%20**The%20values%20themselves**%20(%60%5B5%2C%207%2C%202%5D%60)%3A%20the%20value%20is%20appended%20instead%20of%20the%20total%20so%20far.%0A%20%20%20%20-%20**One%20total%20too%20few%20or%20too%20many**%3A%20append%20once%20per%20value%2C%20after%20adding%20it.%0A%20%20%20%20%22%22%22)%7D)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%208%20%C2%B7%20Notebooks%20as%20files%0A%0A%20%20%20%20**A%20marimo%20notebook%20is%20a%20Python%20file.**%20Open%20%6060_meet_marimo.py%60%20in%20a%20text%20editor%3A%20each%20cell%20is%20a%20function%2C%20with%20the%20names%20it%20uses%20as%20inputs%20and%20the%20names%20it%20defines%20as%20outputs.%20That%20has%20three%20consequences%20that%20matter%20for%20work%20you%20share%3A%0A%0A%20%20%20%20-%20**git%20sees%20real%20changes.**%20A%20Jupyter%20notebook%20is%20JSON%20with%20its%20outputs%20inside%2C%20so%20a%20change%20of%20one%20line%20shows%20in%20git%20as%20pages%20of%20noise.%20A%20marimo%20notebook's%20diff%20is%20its%20code.%0A%20%20%20%20-%20**It%20runs%20as%20a%20script.**%20%60uv%20run%20python%2060_meet_marimo.py%60%20runs%20every%20cell%2C%20in%20order%2C%20without%20a%20browser%3A%20a%20notebook%20can%20become%20a%20step%20of%20a%20pipeline.%0A%20%20%20%20-%20**It%20can%20be%20an%20app.**%20%60uv%20run%20marimo%20run%2060_meet_marimo.py%60%20shows%20the%20notebook%20without%20its%20code%2C%20controls%20and%20all%3A%20a%20small%20app%20for%20someone%20who%20should%20not%20have%20to%20read%20Python.%0A%0A%20%20%20%20**Converting%20a%20Jupyter%20notebook.**%20%60uv%20run%20marimo%20convert%2040_functions.ipynb%20-o%2040_functions_marimo.py%60%20turns%20a%20Jupyter%20notebook%20into%20a%20marimo%20one.%20Try%20it%20on%20one%20of%20this%20course's%20notebooks%2C%20open%20the%20result%2C%20and%20look%20at%20what%20marimo%20flags%3A%20names%20defined%20in%20two%20cells%20(which%20Jupyter%20allowed)%20are%20the%20usual%20first%20thing%20to%20fix.%0A%0A%20%20%20%20**When%20to%20use%20which.**%20Jupyter%20is%20everywhere%3A%20most%20tutorials%2C%20courses%20and%20colleagues%20use%20it%2C%20and%20every%20data%20tool%20reads%20%60.ipynb%60.%20marimo%20is%20better%20when%20a%20notebook%20must%20stay%20right%20as%20it%20changes%2C%20be%20kept%20in%20git%2C%20run%20as%20a%20script%2C%20or%20be%20shared%20as%20an%20app.%20Knowing%20both%2C%20you%20can%20read%20the%20one%20you%20are%20given%20and%20choose%20the%20one%20you%20start.%0A%0A%20%20%20%20The%20next%20course%2C%20**Arrays%20and%20DataFrames**%2C%20is%20taught%20in%20marimo%20from%20its%20first%20module%2C%20with%20NumPy%2C%20pandas%20and%20polars.%20This%20one%20ends%20with%20the%20**capstone**%2C%20back%20in%20Jupyter%3A%20%6070_capstone.ipynb%60.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(course)%3A%0A%20%20%20%20course.quizzes_at(%227.8%22)%0A%20%20%20%20return%0A%0A%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20app.run()%0A
9828222e4965f4e516afd77113778d9e