Loading the chapter…
%23%20%2F%2F%2F%20script%0A%23%20requires-python%20%3D%20%22%3E%3D3.12%2C%3C3.15%22%0A%23%20dependencies%20%3D%20%5B%0A%23%20%20%20%20%20%22marimo%22%2C%0A%23%20%5D%0A%23%20%2F%2F%2F%0A%22%22%22Python%20Handbook%2C%20Chapter%20A%3A%20Essentials.%0A%22%22%22%0A%0Aimport%20marimo%0A%0A__generated_with%20%3D%20%220.25.2%22%0Aapp%20%3D%20marimo.App(width%3D%22medium%22%2C%20sql_output%3D%22polars%22)%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20import%20marimo%20as%20mo%0A%0A%20%20%20%20return%20(mo%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%20%23%20Essentials%0A%0A%20%20%20%20Chapter%20A%20of%20the%20Python%20Handbook.%2010%20sections%2C%20each%20one%20concept.%20Read%20this%20chapter%20and%20you%20can%20write%20a%20program.%0A%0A%20%20%20%20You%20can%20read%20this%20straight%20through%2C%20or%20open%20it%20when%20you%20need%20one%20thing.%20Every%0A%20%20%20%20section%20ends%20with%20three%20questions%20that%20have%20no%20answers%20written%20down%2C%20because%20those%0A%20%20%20%20are%20the%20ones%20asked%20out%20loud%20in%20class.%0A%0A%20%20%20%20To%20run%20the%20code%20yourself%2C%20download%20the%20%60.py%60%20into%20your%20project%20and%20open%20it%20with%0A%20%20%20%20%60uv%20run%20marimo%20edit%60.%0A%20%20%20%20%22%22%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---%0A%20%20%20%20%23%23%201.%20Variables%20and%20values%0A%0A%20%20%20%20A%20name%2C%20which%20most%20books%20and%20every%20job%20posting%20call%20a%20**variable**%2C%20holds%20a%20value.%0A%20%20%20%20Everything%20else%20in%20Python%20is%20built%20on%20this.%20Once%20a%20value%20has%20a%20name%20you%20can%20use%20it%0A%20%20%20%20somewhere%20else%2C%20change%20it%20in%20one%20place%2C%20and%20see%20what%20depended%20on%20it.%0A%0A%20%20%20%20%F0%9F%93%96%20**Used%20in%3A**%20Getting%20everything%20running%0A%20%20%20%20%22%22%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%23%20%60%3D%60%20puts%20a%20value%20into%20a%20name%0A%0A%20%20%20%20Read%20%60freight%20%3D%2016.75%60%20as%20**put%2016.75%20into%20freight**.%20This%20is%20an%20**assignment**%2C%20and%0A%20%20%20%20it%20is%20an%20instruction%2C%20which%20is%20why%20%60freight%20%3D%20freight%20%2B%201%60%20is%20legal.%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%20freight%20%3D%2016.75%0A%20%20%20%20freight%0A%20%20%20%20return%20(freight%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%20%F0%9F%91%89%20**Try%20it%3A**%20change%2016.75%20to%2099.99%20and%20run%20the%20cell.%20Then%20put%20your%20own%20name%20on%20a%0A%20%20%20%20number%20you%20care%20about%20at%20work.%0A%20%20%20%20%22%22%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%23%20Giving%20a%20name%20a%20new%20value%0A%0A%20%20%20%20Nothing%20remembers%20what%20was%20there%20before.%20If%20you%20need%20both%2C%20use%20two%20names.%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%20shipping_cost%20%3D%2016.75%0A%20%20%20%20shipping_cost%20%3D%2022.25%0A%20%20%20%20shipping_cost%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%F0%9F%91%89%20**Try%20it%3A**%20add%20a%20third%20line%2C%20%60shipping_cost%20%3D%20shipping_cost%20*%202%60%2C%20and%20predict%0A%20%20%20%20the%20answer%20before%20you%20run%20it.%0A%20%20%20%20%22%22%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%23%20Names%20in%20expressions%0A%0A%20%20%20%20This%20is%20where%20names%20earn%20their%20keep.%20%60freight%60%20is%20defined%20once%20above%2C%20and%20the%20cell%0A%20%20%20%20below%20uses%20it.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(freight)%3A%0A%20%20%20%20freight_with_handling%20%3D%20freight%20%2B%203.50%0A%20%20%20%20freight_with_handling%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%F0%9F%91%89%20**Try%20it%3A**%20go%20back%20up%20and%20change%20%60freight%60.%20Watch%20this%20cell%20change%20on%20its%20own.%0A%20%20%20%20You%20did%20not%20run%20it.%0A%0A%20%20%20%20**The%20trap.**%20Naming%20something%20does%20not%20copy%20it%20into%20every%20place%20you%20used%20it.%20It%20is%0A%20%20%20%20one%20value%20with%20one%20name%2C%20and%20everything%20reading%20that%20name%20sees%20the%20change.%0A%20%20%20%20%22%22%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%23%20%E2%9C%94%20Check%20your%20understanding%0A%0A%20%20%20%201.%20What%20does%20%60total%20%3D%20total%20%2B%205%60%20do%2C%20given%20that%20%60%3D%60%20does%20not%20mean%20equality%3F%0A%20%20%20%202.%20You%20give%20a%20name%20a%20new%20value.%20What%20happens%20to%20the%20value%20it%20held%20before%3F%0A%20%20%20%203.%20Two%20cells%20both%20use%20%60freight%60.%20You%20change%20%60freight%60%20in%20one%20place.%20How%20many%20values%0A%20%20%20%20%20%20%20of%20%60freight%60%20exist%20now%3F%0A%20%20%20%20%22%22%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---%0A%20%20%20%20%23%23%202.%20Types%0A%0A%20%20%20%20Every%20value%20has%20a%20**type**%2C%20and%20the%20type%20decides%20what%20can%20be%20done%20to%20it.%20Python%0A%20%20%20%20will%20not%20guess%20for%20you.%0A%0A%20%20%20%20%F0%9F%93%96%20**Used%20in%3A**%20Reading%20an%20error%20message%0A%20%20%20%20%22%22%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%23%20The%20types%20you%20will%20meet%20constantly%0A%0A%20%20%20%20%60int%60%20a%20whole%20number.%20%60float%60%20a%20number%20with%20a%20decimal%20point.%20%60str%60%20text%2C%20always%20in%0A%20%20%20%20quotes.%20%60bool%60%2C%20short%20for%20**boolean**%2C%20either%20%60True%60%20or%20%60False%60%2C%20with%20capital%20letters.%0A%0A%20%20%20%20%60type()%60%20tells%20you%20what%20you%20are%20holding.%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%20quantity%20%3D%2012%0A%20%20%20%20unit_price%20%3D%2014.00%0A%20%20%20%20product%20%3D%20%22Queso%20Cabrales%22%0A%20%20%20%20discontinued%20%3D%20False%0A%0A%20%20%20%20type(quantity)%2C%20type(unit_price)%2C%20type(product)%2C%20type(discontinued)%0A%20%20%20%20return%20product%2C%20quantity%2C%20unit_price%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%F0%9F%91%89%20**Try%20it%3A**%20add%20%60type(12%20%2F%204)%60%20and%20predict%20it%20before%20you%20run.%20The%20result%20is%0A%20%20%20%20three%2C%20so%20is%20it%20an%20%60int%60%3F%0A%20%20%20%20%22%22%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%23%20%60%225%22%60%20and%20%605%60%20are%20different%20things%0A%0A%20%20%20%20Quotes%20make%20it%20text.%20Text%20and%20numbers%20behave%20differently%20under%20the%20same%20%60%2B%60%2C%20which%0A%20%20%20%20**concatenates**%20two%20strings%20and%20adds%20two%20numbers.%0A%0A%20%20%20%20%60%60%60python%0A%20%20%20%20%225%22%20%2B%20%223%22%20%20%20%20%20%20%23%20'53'%0A%20%20%20%205%20%2B%203%20%20%20%20%20%20%20%20%20%20%23%208%0A%20%20%20%205%20%2B%20%223%22%20%20%20%20%20%20%20%20%23%20TypeError%3A%20unsupported%20operand%20type(s)%20for%20%2B%3A%20'int'%20and%20'str'%0A%20%20%20%20%60%60%60%0A%0A%20%20%20%20**The%20trap.**%20The%20first%20one%20does%20not%20fail.%20It%20succeeds%20and%20gives%20you%20%60'53'%60%2C%20which%0A%20%20%20%20is%20how%20a%20wrong%20number%20reaches%20a%20slide.%20Anything%20read%20from%20a%20file%2C%20a%20form%2C%20or%20a%20web%0A%20%20%20%20page%20arrives%20as%20%60str%60%20until%20you%20convert%20it.%0A%20%20%20%20%22%22%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%F0%9F%91%89%20**Try%20it%3A**%20run%20all%20three%20lines%20above%20in%20a%20cell%20of%20your%20own%2C%20one%20at%20a%20time.%20The%0A%20%20%20%20third%20one%20is%20supposed%20to%20fail.%20Read%20what%20it%20says.%0A%20%20%20%20%22%22%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%23%20Converting%20between%20types%0A%0A%20%20%20%20%60int()%60%2C%20%60float()%60%20and%20%60str()%60%20take%20a%20value%20and%20hand%20back%20a%20new%20one%20of%20that%20type.%0A%20%20%20%20Converting%20like%20this%20is%20called%20**casting**.%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%20quantity_from_form%20%3D%20%2212%22%0A%20%20%20%20quantity_as_number%20%3D%20int(quantity_from_form)%0A%0A%20%20%20%20quantity_as_number%20%2B%203%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%F0%9F%91%89%20**Try%20it%3A**%20what%20does%20%60int(%2212.5%22)%60%20do%3F%20Predict%2C%20then%20run.%20Then%20try%0A%20%20%20%20%60int(float(%2212.5%22))%60.%0A%20%20%20%20%22%22%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%23%20The%20difference%20between%20%60%2F%60%20and%20%60%2F%2F%60%0A%0A%20%20%20%20%60%2F%60%20always%20gives%20a%20%60float%60.%20%60%2F%2F%60%20is%20**floor%20division**%2C%20which%20throws%20away%20the%0A%20%20%20%20remainder%2C%20and%20%60%25%60%20is%20**modulo**%2C%20which%20keeps%20it.%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%2017%20%2F%205%2C%2017%20%2F%2F%205%2C%2017%20%25%205%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%F0%9F%91%89%20**Try%20it%3A**%20you%20have%2017%20units%20and%20a%20case%20holds%205.%20How%20many%20full%20cases%2C%20and%20how%0A%20%20%20%20many%20left%20over%3F%20Write%20it%20with%20the%20two%20operators%20above.%0A%20%20%20%20%22%22%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%23%20In%20Excel%20terms%0A%0A%20%20%20%20Excel%20converts%20for%20you%20and%20mostly%20guesses%20right%2C%20which%20is%20why%20a%20leading%20zero%0A%20%20%20%20disappears%20from%20a%20product%20code%20and%20a%20date%20turns%20into%2045231.%20Python%20refuses%20instead%0A%20%20%20%20of%20guessing%2C%20so%20the%20failure%20arrives%20while%20you%20are%20writing%20the%20line.%0A%0A%20%20%20%20%23%23%23%20%E2%9C%94%20Check%20your%20understanding%0A%0A%20%20%20%201.%20%60%225%22%20%2B%20%223%22%60%20gives%20%60'53'%60%20and%20%605%20%2B%20%223%22%60%20raises%20an%20error.%20Which%20of%20the%20two%20is%20more%0A%20%20%20%20%20%20%20dangerous%20in%20a%20report%2C%20and%20why%3F%0A%20%20%20%202.%20A%20CSV%20column%20of%20prices%20comes%20in%20as%20%60str%60.%20What%20has%20to%20happen%20before%20you%20can%20add%0A%20%20%20%20%20%20%20them%20up%3F%0A%20%20%20%203.%20%6010%20%2F%202%60%20gives%20%605.0%60%20and%20%6010%20%2F%2F%202%60%20gives%20%605%60.%20When%20does%20the%20difference%20matter%3F%0A%20%20%20%20%22%22%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---%0A%20%20%20%20%23%23%203.%20Expressions%20and%20operators%0A%0A%20%20%20%20An%20expression%20is%20anything%20that%20produces%20a%20value.%20Operators%20are%20what%20combine%0A%20%20%20%20values%2C%20and%20the%20order%20they%20apply%20in%20is%20fixed.%0A%0A%20%20%20%20%F0%9F%93%96%20**Used%20in%3A**%20Reading%20an%20error%20message%0A%20%20%20%20%22%22%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%23%20Arithmetic%0A%0A%20%20%20%20%60%2B%60%20%60-%60%20%60*%60%20%60%2F%60%20you%20know.%20%60**%60%20is%20**exponentiation**%2C%20and%20%60%25%60%20is%20the%20remainder.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(quantity%2C%20unit_price)%3A%0A%20%20%20%20line_total%20%3D%20quantity%20*%20unit_price%0A%20%20%20%20line_total%0A%20%20%20%20return%20(line_total%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%20%F0%9F%91%89%20**Try%20it%3A**%20compute%20the%20line%20total%20with%20a%2015%20percent%20discount%20applied.%20There%20is%0A%20%20%20%20more%20than%20one%20way%20to%20write%20it.%0A%20%20%20%20%22%22%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%23%20Precedence%20and%20parentheses%0A%0A%20%20%20%20%60*%60%20and%20%60%2F%60%20happen%20before%20%60%2B%60%20and%20%60-%60%2C%20the%20same%20rule%20as%20arithmetic%20class%20and%20the%0A%20%20%20%20same%20rule%20as%20Excel.%20The%20two%20lines%20below%20are%20different%20calculations.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(line_total)%3A%0A%20%20%20%20without_parens%20%3D%20line_total%20%2B%2016.75%20*%200.5%0A%20%20%20%20with_parens%20%3D%20(line_total%20%2B%2016.75)%20*%200.5%0A%0A%20%20%20%20without_parens%2C%20with_parens%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%F0%9F%91%89%20**Try%20it%3A**%20write%20the%20same%20calculation%20in%20a%20way%20that%20needs%20no%20parentheses%20at%20all.%0A%20%20%20%20Which%20version%20would%20a%20colleague%20read%20faster%3F%0A%0A%20%20%20%20**The%20trap.**%20Nothing%20warns%20you.%20Both%20lines%20run%2C%20and%20only%20one%20of%20them%20is%20the%20number%0A%20%20%20%20you%20meant.%0A%20%20%20%20%22%22%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%23%20Comparisons%20produce%20%60True%60%20or%20%60False%60%0A%0A%20%20%20%20%60%3D%3D%60%20%60!%3D%60%20%60%3C%60%20%60%3C%3D%60%20%60%3E%60%20%60%3E%3D%60.%20Note%20that%20comparison%20is%20%60%3D%3D%60%2C%20with%20two%20signs%2C%20because%0A%20%20%20%20one%20sign%20already%20means%20assignment.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(line_total)%3A%0A%20%20%20%20is_large_order%20%3D%20line_total%20%3E%20100%0A%20%20%20%20is_large_order%0A%20%20%20%20return%20(is_large_order%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%20%F0%9F%91%89%20**Try%20it%3A**%20write%20a%20comparison%20that%20is%20%60True%60%20for%20this%20order%20and%20%60False%60%20for%20one%0A%20%20%20%20worth%2050.%0A%20%20%20%20%22%22%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%23%20%60and%60%2C%20%60or%60%2C%20%60not%60%0A%0A%20%20%20%20These%20combine%20comparisons.%20%60and%60%20needs%20both%20sides%20true%3B%20%60or%60%20needs%20one.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(is_large_order%2C%20product)%3A%0A%20%20%20%20ships_free%20%3D%20is_large_order%20and%20not%20product.startswith(%22Perishable%22)%0A%20%20%20%20ships_free%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%F0%9F%91%89%20**Try%20it%3A**%20both%20sides%20are%20%60True%60%20here%2C%20so%20%60and%60%20and%20%60or%60%20agree%20and%20swapping%20them%0A%20%20%20%20proves%20nothing.%20Make%20one%20side%20false%3A%20replace%20%60is_large_order%60%20with%20%60line_total%20%3E%20200%60%2C%0A%20%20%20%20run%20it%2C%20then%20swap%20%60and%60%20for%20%60or%60.%20Now%20they%20differ%2C%20and%20the%20difference%20is%20the%20point.%0A%0A%20%20%20%20%23%23%23%20%E2%9C%94%20Check%20your%20understanding%0A%0A%20%20%20%201.%20Why%20does%20Python%20need%20%60%3D%3D%60%20for%20comparison%20instead%20of%20reusing%20%60%3D%60%3F%0A%20%20%20%202.%20%602%20%2B%203%20*%204%60%20gives%2014.%20What%20would%20you%20write%20to%20get%2020%3F%0A%20%20%20%203.%20%60a%20and%20b%60%20is%20%60False%60.%20What%20do%20you%20know%20about%20%60a%60%3F%20What%20do%20you%20know%20about%20%60b%60%3F%0A%20%20%20%20%22%22%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---%0A%20%20%20%20%23%23%204.%20Conditionals%0A%0A%20%20%20%20A%20conditional%20runs%20one%20block%20of%20code%20or%20another%20depending%20on%20a%20comparison.%20It%20is%0A%20%20%20%20the%20first%20place%20where%20code%20stops%20being%20a%20calculator.%0A%0A%20%20%20%20%F0%9F%93%96%20**Used%20in%3A**%20What%20one%20row%20means%0A%20%20%20%20%22%22%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%23%20%60if%60%2C%20%60elif%60%2C%20%60else%60%0A%0A%20%20%20%20The%20line%20ends%20in%20a%20colon%20and%20the%20block%20underneath%20is%20indented.%20The%20indentation%20is%0A%20%20%20%20not%20decoration%3B%20it%20is%20how%20Python%20knows%20what%20belongs%20to%20the%20%60if%60.%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%20order_value%20%3D%20240.00%0A%0A%20%20%20%20if%20order_value%20%3E%3D%20500%3A%0A%20%20%20%20%20%20%20%20tier%20%3D%20%22A%22%0A%20%20%20%20elif%20order_value%20%3E%3D%20200%3A%0A%20%20%20%20%20%20%20%20tier%20%3D%20%22B%22%0A%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20tier%20%3D%20%22C%22%0A%0A%20%20%20%20tier%0A%20%20%20%20return%20(order_value%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%20%F0%9F%91%89%20**Try%20it%3A**%20set%20%60order_value%60%20to%20500%2C%20then%20to%20499.99%2C%20then%20to%20200.%20Predict%20the%0A%20%20%20%20tier%20each%20time%20before%20you%20run.%0A%20%20%20%20%22%22%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%23%20Choosing%20the%20boundary%0A%0A%20%20%20%20%60%3E%3D%20500%60%20and%20%60%3E%20500%60%20differ%20for%20exactly%20one%20order%20value%2C%20and%20that%20difference%20is%20a%0A%20%20%20%20business%20rule.%20Whoever%20writes%20the%20comparison%20has%20made%20the%20call.%0A%0A%20%20%20%20**The%20trap.**%20An%20agent%20asked%20to%20%22tier%20orders%20above%20500%22%20will%20pick%20one%20of%20the%20two%0A%20%20%20%20without%20telling%20you%20which.%20Read%20the%20operator.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(order_value)%3A%0A%20%20%20%20order_value%20%3E%3D%20500%2C%20order_value%20%3E%20500%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%F0%9F%91%89%20**Try%20it%3A**%20set%20%60order_value%60%20to%20exactly%20500%20and%20run%20the%20cell%20above.%20Now%20decide%0A%20%20%20%20which%20of%20the%20two%20lines%20matches%20the%20rule%20your%20company%20actually%20uses.%0A%20%20%20%20%22%22%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%23%20Why%20the%20order%20of%20conditions%20matters%0A%0A%20%20%20%20Python%20checks%20the%20branches%20from%20the%20top%20and%20stops%20at%20the%20first%20one%20that%20is%20%60True%60.%0A%20%20%20%20Put%20the%20narrowest%20condition%20first.%0A%0A%20%20%20%20%60%60%60python%0A%20%20%20%20%23%20Wrong.%20Every%20order%20over%20200%20is%20caught%20here%2C%20including%20the%20ones%20over%20500.%0A%20%20%20%20if%20order_value%20%3E%3D%20200%3A%0A%20%20%20%20%20%20%20%20tier%20%3D%20%22B%22%0A%20%20%20%20elif%20order_value%20%3E%3D%20500%3A%0A%20%20%20%20%20%20%20%20tier%20%3D%20%22A%22%0A%20%20%20%20%60%60%60%0A%0A%20%20%20%20Nothing%20errors.%20Tier%20A%20simply%20never%20happens.%0A%20%20%20%20%22%22%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%F0%9F%91%89%20**Try%20it%3A**%20copy%20that%20broken%20version%20into%20a%20cell%2C%20set%20%60order_value%60%20to%20900%2C%20and%0A%20%20%20%20confirm%20that%20it%20says%20B.%20**Rename%20%60tier%60%20to%20%60tier_broken%60%20in%20your%20copy**%3A%20a%20name%20is%0A%20%20%20%20defined%20in%20exactly%20one%20cell%20here%2C%20so%20a%20second%20%60tier%60%20is%20a%20multiple-definitions%20error%0A%20%20%20%20rather%20than%20the%20lesson.%0A%0A%20%20%20%20%23%23%23%20%E2%9C%94%20Check%20your%20understanding%0A%0A%20%20%20%201.%20What%20tells%20Python%20which%20lines%20belong%20to%20an%20%60if%60%20block%3F%0A%20%20%20%202.%20Your%20rule%20is%20%22over%20500%20gets%20tier%20A%22.%20Which%20comparison%20is%20that%2C%20and%20what%20happens%0A%20%20%20%20%20%20%20to%20an%20order%20of%20exactly%20500%3F%0A%20%20%20%203.%20A%20chain%20has%20four%20branches%20and%20the%20third%20one%20never%20runs.%20What%20would%20you%20look%20at%0A%20%20%20%20%20%20%20first%3F%0A%20%20%20%20%22%22%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---%0A%20%20%20%20%23%23%205.%20Strings%0A%0A%20%20%20%20Text%20is%20the%20type%20most%20business%20data%20arrives%20in%3A%20names%2C%20cities%2C%20product%20codes%2C%0A%20%20%20%20anything%20typed%20by%20a%20person.%20Cleaning%20it%20is%20most%20of%20the%20work%20in%20the%20first%20hour%20of%20a%0A%20%20%20%20real%20dataset.%0A%20%20%20%20%22%22%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%23%20Quotes%2C%20length%2C%20and%20one%20character%20at%20a%20time%0A%0A%20%20%20%20Single%20or%20double%20quotes%2C%20and%20it%20makes%20no%20difference%20which.%20%60len()%60%20counts%0A%20%20%20%20characters.%20A%20position%20in%20brackets%2C%20its%20**index**%2C%20picks%20one%20out%2C%20**counting%20from%0A%20%20%20%20zero**%2C%20and%20a%20negative%20index%20counts%20from%20the%20end.%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%20customer%20%3D%20%22Alfreds%20Futterkiste%22%0A%0A%20%20%20%20len(customer)%2C%20customer%5B0%5D%2C%20customer%5B-1%5D%0A%20%20%20%20return%20(customer%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%20%F0%9F%91%89%20**Try%20it%3A**%20which%20position%20holds%20the%20space%3F%20Find%20it%20by%20guessing%2C%20then%20check.%0A%20%20%20%20%22%22%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%23%20Slicing%20takes%20a%20range%0A%0A%20%20%20%20%60customer%5B0%3A7%5D%60%20reads%20as%20**from%200%20up%20to%20but%20not%20including%207**.%20Leave%20a%20side%20empty%0A%20%20%20%20to%20mean%20%22from%20the%20start%22%20or%20%22to%20the%20end%22.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(customer)%3A%0A%20%20%20%20customer%5B0%3A7%5D%2C%20customer%5B8%3A%5D%2C%20customer%5B%3A7%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%F0%9F%91%89%20**Try%20it%3A**%20pull%20out%20the%20last%20four%20characters%20two%20different%20ways%2C%20one%20with%20a%0A%20%20%20%20negative%20number%20and%20one%20without.%0A%0A%20%20%20%20**The%20trap.**%20The%20end%20position%20is%20not%20included.%20%60customer%5B0%3A7%5D%60%20gives%20you%20seven%0A%20%20%20%20characters%2C%20not%20eight.%0A%20%20%20%20%22%22%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%23%20Methods%20do%20the%20cleaning%0A%0A%20%20%20%20A%20method%20is%20written%20after%20a%20dot.%20These%20three%20cover%20most%20of%20what%20a%20messy%20column%0A%20%20%20%20needs%2C%20and%20%60len()%60%20from%20a%20moment%20ago%20is%20the%20fourth%20thing%20you%20will%20reach%20for.%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%20city_raw%20%3D%20%22%20%20Berlin%20%20%22%0A%0A%20%20%20%20city_raw.strip()%2C%20city_raw.strip().lower()%2C%20%22Sales-Q3%22.replace(%22-%22%2C%20%22%20%22)%0A%20%20%20%20return%20(city_raw%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%20%F0%9F%91%89%20**Try%20it%3A**%20%60%22%20%20BERLIN%20%22.strip().lower()%60%20and%20%60%22Berlin%22.lower().strip()%60%20give%20the%0A%20%20%20%20same%20answer.%20Is%20that%20always%20true%20for%20any%20pair%20of%20methods%3F%0A%20%20%20%20%22%22%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%23%20Strings%20do%20not%20change%0A%0A%20%20%20%20A%20string%20is%20**immutable**%2C%20so%20a%20method%20hands%20back%20a%20**new**%20string%20and%20leaves%20the%0A%20%20%20%20original%20alone.%20This%20catches%20everybody%20once.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(city_raw)%3A%0A%20%20%20%20city_raw.strip()%0A%20%20%20%20city_raw%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%20The%20second%20line%20still%20shows%20the%20spaces.%20Nothing%20was%20saved.%0A%0A%20%20%20%20%F0%9F%91%89%20**Try%20it%3A**%20fix%20it%20by%20putting%20the%20result%20into%20a%20name%3A%0A%20%20%20%20%60city_clean%20%3D%20city_raw.strip()%60.%0A%20%20%20%20%22%22%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%23%20From%20one%20field%20to%20a%20list%20and%20back%0A%0A%20%20%20%20One%20string%20often%20holds%20several%20values%20with%20something%20between%20them%2C%20which%20is%20how%20a%0A%20%20%20%20spreadsheet%20column%20and%20an%20API%20both%20hand%20you%20a%20list%20without%20calling%20it%20one.%0A%20%20%20%20%60.split()%60%20cuts%20at%20the%20separator%20and%20gives%20back%20a%20**list**.%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%20watchlist%20%3D%20%22AAPL%2CMSFT%2CGOOG%2CAMZN%22%0A%20%20%20%20tickers%20%3D%20watchlist.split(%22%2C%22)%0A%0A%20%20%20%20tickers%2C%20len(tickers)%0A%20%20%20%20return%20(tickers%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%20%60.join()%60%20is%20the%20return%20trip%2C%20and%20it%20is%20written%20on%20the%20separator%20rather%20than%20on%20the%0A%20%20%20%20list%2C%20which%20reads%20backwards%20the%20first%20time%20you%20see%20it.%20The%20string%20in%20front%20is%20what%0A%20%20%20%20goes%20**between**%20the%20items%2C%20so%20it%20appears%20three%20times%20in%20a%20list%20of%20four%20and%20never%20at%0A%20%20%20%20either%20end.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(tickers)%3A%0A%20%20%20%20%22%2C%20%22.join(tickers)%2C%20%22%20%7C%20%22.join(tickers)%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%F0%9F%91%89%20**Try%20it%3A**%20split%20%60%22AAPL%2C%20MSFT%2C%20GOOG%22%60%2C%20which%20has%20a%20space%20after%20each%20comma%2C%20and%0A%20%20%20%20look%20at%20what%20the%20second%20ticker%20actually%20is.%20Fix%20it%20two%20ways%2C%20one%20by%20splitting%20on%20a%0A%20%20%20%20different%20separator%20and%20one%20with%20%60.strip()%60.%0A%0A%20%20%20%20**The%20trap.**%20A%20separator%20that%20is%20not%20there%20gives%20you%20a%20list%20of%20one%2C%20not%20an%20error%3A%0A%20%20%20%20%60%22AAPL%2CMSFT%22.split(%22%3B%22)%60%20returns%20%60%5B'AAPL%2CMSFT'%5D%60.%20And%20%60.split()%60%20with%20nothing%20in%20the%0A%20%20%20%20brackets%20is%20a%20different%20operation%2C%20splitting%20on%20any%20run%20of%20whitespace%2C%20which%20is%20what%0A%20%20%20%20you%20want%20for%20%60%22Alfreds%20Futterkiste%22.split()%60%20and%20never%20what%20you%20want%20for%20a%20comma.%0A%20%20%20%20%22%22%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%23%20Asking%20a%20string%20a%20question%0A%0A%20%20%20%20Three%20of%20these%20answer%20yes%20or%20no%2C%20and%20they%20are%20how%20a%20column%20gets%20filtered%20before%0A%20%20%20%20anything%20is%20computed%20from%20it.%20%60in%60%20is%20not%20a%20method%20and%20needs%20no%20dot.%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%20product_code%20%3D%20%22PROD-1084%22%0A%0A%20%20%20%20(%0A%20%20%20%20%20%20%20%20product_code.startswith(%22PROD%22)%2C%0A%20%20%20%20%20%20%20%20product_code.endswith(%2284%22)%2C%0A%20%20%20%20%20%20%20%20%221084%22%20in%20product_code%2C%0A%20%20%20%20%20%20%20%20product_code.isdigit()%2C%0A%20%20%20%20)%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**The%20trap.**%20%60.isdigit()%60%20is%20%60True%60%20only%20when%20**every**%20character%20is%20a%20digit%2C%20so%0A%20%20%20%20%60%2216.75%22.isdigit()%60%20is%20%60False%60%20because%20of%20the%20dot%20and%20%60%22-4%22.isdigit()%60%20is%20%60False%60%0A%20%20%20%20because%20of%20the%20minus%20sign.%20Both%20of%20those%20go%20into%20%60float()%60%20without%20complaint.%20It%20is%20a%0A%20%20%20%20narrower%20question%20than%20%22is%20this%20a%20number%22%2C%20and%20reaching%20for%20it%20to%20decide%20whether%20a%0A%20%20%20%20column%20can%20be%20converted%20throws%20away%20the%20decimals.%0A%0A%20%20%20%20%F0%9F%91%89%20**Try%20it%3A**%20run%20%60%2216.75%22.isdigit()%60%20and%20then%20%60float(%2216.75%22)%60.%20One%20says%20no%20and%20the%0A%20%20%20%20other%20works.%20Explain%20in%20one%20sentence%20what%20each%20of%20them%20is%20asking.%0A%20%20%20%20%22%22%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%23%20In%20Excel%20terms%0A%0A%20%20%20%20%60LEN%60%20is%20%60len()%60%2C%20%60TRIM%60%20is%20%60.strip()%60%2C%20%60LOWER%60%20is%20%60.lower()%60%2C%20%60SUBSTITUTE%60%20is%0A%20%20%20%20%60.replace()%60%2C%20%60MID%60%20is%20slicing%2C%20%60TEXTSPLIT%60%20is%20%60.split()%60%20and%20%60TEXTJOIN%60%20is%0A%20%20%20%20%60.join()%60.%20The%20one%20real%20difference%20is%20that%20Excel%20counts%20from%201%20and%20Python%20counts%0A%20%20%20%20from%200.%0A%0A%20%20%20%20%23%23%23%20%E2%9C%94%20Check%20your%20understanding%0A%0A%20%20%20%201.%20%60customer%5B0%3A7%5D%60%20returns%20how%20many%20characters%2C%20and%20why%20is%20that%20not%20eight%3F%0A%20%20%20%202.%20You%20call%20%60.strip()%60%20on%20a%20name%20and%20the%20spaces%20are%20still%20there%20when%20you%20print%20it.%0A%20%20%20%20%20%20%20What%20did%20you%20forget%3F%0A%20%20%20%203.%20Excel's%20%60MID(A1%2C%201%2C%207)%60%20and%20Python's%20%60customer%5B0%3A7%5D%60%20return%20the%20same%20text.%20Why%20do%0A%20%20%20%20%20%20%20the%20numbers%20differ%3F%0A%20%20%20%204.%20%60%22%2C%20%22.join(tickers)%60%20puts%20a%20comma%20and%20a%20space%20between%20the%20tickers.%20How%20many%20times%0A%20%20%20%20%20%20%20does%20it%20appear%20in%20a%20list%20of%20four%2C%20and%20where%20does%20it%20not%20appear%3F%0A%20%20%20%205.%20%60%2216.75%22.isdigit()%60%20is%20%60False%60%20and%20%60float(%2216.75%22)%60%20works.%20What%20is%20each%20one%20asking%3F%0A%20%20%20%20%22%22%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---%0A%20%20%20%20%23%23%206.%20f-strings%0A%0A%20%20%20%20An%20f-string%20builds%20a%20sentence%20with%20values%20in%20it.%20Every%20number%20you%20report%20to%0A%20%20%20%20somebody%20goes%20through%20one%2C%20and%20the%20formatting%20is%20where%20a%20raw%20number%20becomes%0A%20%20%20%20readable.%0A%0A%20%20%20%20%F0%9F%93%96%20**Used%20in%3A**%20Reading%20an%20error%20message%0A%20%20%20%20%22%22%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%23%20The%20%60f%60%20and%20the%20braces%0A%0A%20%20%20%20Anything%20inside%20%60%7B%7D%60%20is%20evaluated%20and%20dropped%20into%20the%20text.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(customer%2C%20line_total)%3A%0A%20%20%20%20f%22%7Bcustomer%7D%20ordered%20%7Bline_total%7D%20of%20product.%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%F0%9F%91%89%20**Try%20it%3A**%20put%20a%20calculation%20inside%20the%20braces%2C%20such%20as%20%60%7Bline_total%20*%202%7D%60.%0A%0A%20%20%20%20**The%20trap.**%20Forget%20the%20%60f%60%20and%20you%20get%20the%20braces%20printed%20literally%2C%20with%20no%0A%20%20%20%20error%20at%20all%3A%0A%0A%20%20%20%20%60%60%60python%0A%20%20%20%20%22%7Bcustomer%7D%20ordered%20%7Bline_total%7D%22%20%20%20%20%20%23%20'%7Bcustomer%7D%20ordered%20%7Bline_total%7D'%0A%20%20%20%20%60%60%60%0A%20%20%20%20%22%22%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%23%20Formatting%20after%20a%20colon%0A%0A%20%20%20%20%60%3A.2f%60%20fixes%20two%20decimal%20places.%20%60%3A%2C%60%20adds%20thousands%20separators.%20%60%3A.1%25%60%20turns%0A%20%20%20%200.153%20into%20%6015.3%25%60.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(line_total)%3A%0A%20%20%20%20f%22%7Bline_total%3A.2f%7D%22%2C%20f%22%7Bline_total%20*%201000%3A%2C.2f%7D%22%2C%20f%22%7B0.153%3A.1%25%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%F0%9F%91%89%20**Try%20it%3A**%20write%20one%20line%20that%20reads%20%60Freight%3A%20%2416.75%60%20using%20a%20name%20instead%20of%0A%20%20%20%20typing%20the%20number.%0A%0A%20%20%20%20%23%23%23%20%E2%9C%94%20Check%20your%20understanding%0A%0A%20%20%20%201.%20You%20print%20a%20line%20and%20see%20%60%7Btotal%7D%60%20in%20the%20output.%20What%20is%20missing%3F%0A%20%20%20%202.%20What%20does%20%60%3A.2f%60%20change%20about%20the%20value%2C%20and%20what%20does%20it%20change%20about%20the%0A%20%20%20%20%20%20%20stored%20number%3F%0A%20%20%20%203.%20When%20would%20you%20want%20%60%3A%2C%60%20and%20when%20would%20it%20be%20wrong%3F%0A%20%20%20%20%22%22%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---%0A%20%20%20%20%23%23%207.%20Dates%20and%20times%0A%0A%20%20%20%20Every%20business%20question%20with%20the%20word%20*when*%20in%20it%20runs%20through%20a%20date.%20How%20long%20did%0A%20%20%20%20that%20take%2C%20was%20it%20late%2C%20how%20many%20shipped%20last%20month.%20Dates%20are%20the%20type%20that%20behaves%0A%20%20%20%20least%20like%20you%20expect%2C%20so%20they%20get%20their%20own%20section%20before%20you%20meet%20a%20whole%20column%20of%0A%20%20%20%20them.%0A%0A%20%20%20%20%F0%9F%93%96%20**Used%20in%3A**%20Building%20and%20querying%20your%20database%20%C2%B7%20Building%20your%20product%0A%20%20%20%20%22%22%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%23%20Dates%20as%20a%20type%0A%0A%20%20%20%20%60%222016-07-04%22%60%20is%20a%20string.%20It%20is%20ten%20characters%20that%20happen%20to%20read%20as%20a%20date%2C%20and%0A%20%20%20%20Python%20will%20let%20you%20compare%20it%2C%20sort%20it%20and%20add%20it%20to%20another%20string.%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%20from%20datetime%20import%20date%0A%0A%20%20%20%20ordered%20%3D%20date(2016%2C%207%2C%204)%0A%20%20%20%20ordered%2C%20type(ordered)%0A%20%20%20%20return%20date%2C%20ordered%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%F0%9F%91%89%20**Try%20it%3A**%20run%20%60type(%222016-07-04%22)%60%20beside%20it.%20Both%20print%20something%20that%20reads%20like%0A%20%20%20%20a%20date.%20Only%20one%20of%20them%20knows%20what%20a%20month%20is.%0A%20%20%20%20%22%22%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%23%20Parsing%20text%20into%20dates%0A%0A%20%20%20%20A%20file%2C%20a%20form%20and%20an%20API%20all%20hand%20you%20a%20string.%20%60date.fromisoformat%60%20turns%0A%20%20%20%20%60YYYY-MM-DD%60%20into%20a%20real%20date.%0A%0A%20%20%20%20**The%20trap.**%20Comparing%20the%20strings%20instead%20works%20most%20of%20the%20time%2C%20which%20is%20what%20makes%0A%20%20%20%20it%20dangerous.%20%60%222016-07-04%22%20%3C%20%222016-07-16%22%60%20is%20%60True%60%20and%20correct.%20Change%20the%20format%0A%20%20%20%20and%20it%20stops%20being%20correct%20while%20still%20being%20%60True%60%20or%20%60False%60.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(date)%3A%0A%20%20%20%20shipped%20%3D%20date.fromisoformat(%222016-07-16%22)%0A%0A%20%20%20%20shipped%2C%20%229%2F9%2F2016%22%20%3C%20%2210%2F1%2F2016%22%0A%20%20%20%20return%20(shipped%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%20The%20second%20answer%20is%20%60False%60.%20As%20text%2C%20%60%229%22%60%20comes%20after%20%60%221%22%60%2C%20so%20September%20beats%0A%20%20%20%20October.%20As%20dates%20it%20is%20obviously%20the%20other%20way%20round%2C%20and%20nothing%20raised.%0A%0A%20%20%20%20%F0%9F%91%89%20**Try%20it%3A**%20parse%20both%20of%20those%20with%20%60date.fromisoformat%60%20and%20compare%20them%20again.%0A%20%20%20%20You%20will%20have%20to%20rewrite%20them%20first%2C%20which%20is%20the%20point.%0A%20%20%20%20%22%22%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%23%20Subtracting%20dates%0A%0A%20%20%20%20Order%20%6010248%60%20was%20placed%20on%204%20July%20and%20shipped%20on%2016%20July.%20The%20difference%20is%20a%0A%20%20%20%20%60timedelta%60%2C%20and%20%60.days%60%20gets%20the%20number%20out%20of%20it.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(ordered%2C%20shipped)%3A%0A%20%20%20%20took%20%3D%20shipped%20-%20ordered%0A%0A%20%20%20%20took%2C%20type(took)%2C%20took.days%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%F0%9F%91%89%20**Try%20it%3A**%20the%20other%20four%20orders%20in%20that%20week%20took%205%2C%204%2C%207%20and%202%20days.%20Compute%20the%0A%20%20%20%20slowest%20one%20as%20a%20%60timedelta%60%20and%20then%20as%20a%20plain%20number%20of%20days.%0A%0A%20%20%20%20**The%20trap.**%20%60took%60%20prints%20as%20%6012%20days%2C%200%3A00%3A00%60%20and%20is%20not%20the%20number%2012.%20Put%20it%20in%20a%0A%20%20%20%20sentence%20and%20you%20get%20the%20whole%20thing.%20%60took.days%60%20is%20the%20number.%0A%20%20%20%20%22%22%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%23%20Timestamps%20against%20dates%0A%0A%20%20%20%20%60date%60%20holds%20a%20day.%20%60datetime%60%20holds%20a%20day%20**and%20a%20time**%2C%20and%20it%20prints%20in%20a%20way%20that%0A%20%20%20%20hides%20the%20difference%20when%20the%20time%20happens%20to%20be%20midnight.%0A%0A%20%20%20%20In%20this%20course's%20warehouse%2C%20%60OrderDate%60%20is%20a%20timestamp.%20**15%2C452%20of%20its%2016%2C282%20orders%0A%20%20%20%20carry%20a%20real%20clock%20time%20and%20830%20do%20not**%2C%20so%20a%20comparison%20against%20a%20bare%20date%20matches%0A%20%20%20%20only%20the%20830.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(date)%3A%0A%20%20%20%20from%20datetime%20import%20datetime%0A%0A%20%20%20%20stamped%20%3D%20datetime(2016%2C%207%2C%204%2C%2015%2C%2040%2C%2046)%0A%20%20%20%20plain%20%3D%20date(2016%2C%207%2C%204)%0A%0A%20%20%20%20stamped.date()%20%3D%3D%20plain%2C%20stamped%20%3D%3D%20datetime(2016%2C%207%2C%204)%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%20The%20first%20is%20%60True%60%2C%20because%20%60.date()%60%20throws%20the%20clock%20away.%20The%20second%20is%20%60False%60%2C%0A%20%20%20%20because%2015%3A40%3A46%20is%20not%20midnight.%20**Neither%20raised.**%0A%0A%20%20%20%20%F0%9F%91%89%20**Try%20it%3A**%20change%20%6015%2C%2040%2C%2046%60%20to%20%600%2C%200%2C%200%60%20and%20run%20it%20again.%20The%20second%20answer%20flips%2C%20and%20that%0A%20%20%20%20is%20exactly%20why%20a%20filter%20can%20look%20correct%20on%20the%20rows%20you%20checked.%0A%0A%20%20%20%20%23%23%23%20%E2%9C%94%20Check%20your%20understanding%0A%0A%20%20%20%201.%20%60%222016-07-04%22%60%20and%20%60date(2016%2C%207%2C%204)%60%20both%20print%20as%20a%20date.%20Name%20one%20thing%20you%20can%0A%20%20%20%20%20%20%20do%20with%20the%20second%20that%20you%20cannot%20do%20with%20the%20first.%0A%20%20%20%202.%20%60shipped%20-%20ordered%60%20gives%20%6012%20days%2C%200%3A00%3A00%60.%20What%20do%20you%20write%20to%20get%20%6012%60%3F%0A%20%20%20%203.%20A%20filter%20on%20%60OrderDate%20%3D%202016-07-04%60%20returns%20six%20rows%20out%20of%20a%20table%20you%20know%20is%0A%20%20%20%20%20%20%20larger.%20Give%20one%20explanation%20that%20does%20not%20involve%20the%20data%20being%20wrong.%0A%20%20%20%20%22%22%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---%0A%20%20%20%20%23%23%208.%20Functions%0A%0A%20%20%20%20A%20function%20is%20a%20calculation%20with%20a%20name.%20You%20write%20it%20once%20and%20call%20it%20wherever%20you%0A%20%20%20%20need%20it%2C%20and%20the%20name%20is%20what%20somebody%20else%20reads%20instead%20of%20the%20arithmetic.%0A%0A%20%20%20%20It%20is%20also%20the%20unit%20an%20agent%20works%20in.%20*%22Write%20a%20function%20that%20takes%20an%20order's%20lines%0A%20%20%20%20and%20returns%20the%20total%22*%20is%20a%20request%20that%20can%20be%20checked.%20*%22Clean%20up%20my%20data%22*%20is%20not.%0A%0A%20%20%20%20%F0%9F%93%96%20**Used%20in%3A**%20Getting%20data%20from%20an%20API%0A%20%20%20%20%22%22%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%23%20%60def%60%2C%20a%20parameter%2C%20and%20%60return%60%0A%0A%20%20%20%20The%20line%20ends%20in%20a%20colon%20and%20the%20body%20is%20indented%2C%20the%20same%20shape%20as%20an%20%60if%60.%20The%0A%20%20%20%20names%20in%20the%20definition%20are%20the%20**parameters**%2C%20and%20the%20values%20you%20hand%20it%20when%20you%0A%20%20%20%20call%20it%20are%20the%20**arguments**.%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%20def%20line_amount(qty%2C%20price)%3A%0A%20%20%20%20%20%20%20%20return%20qty%20*%20price%0A%0A%20%20%20%20line_amount(12%2C%2014.00)%0A%20%20%20%20return%20(line_amount%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%20That%20is%20the%20Queso%20Cabrales%20line%20on%20order%20%6010248%60%2C%20and%20168.00%20is%20the%20number%20you%20would%0A%20%20%20%20check%20by%20hand.%0A%0A%20%20%20%20%F0%9F%91%89%20**Try%20it%3A**%20call%20it%20for%20the%20other%20two%20lines%2C%205%20at%2034.80%20and%2010%20at%209.80.%20Then%20call%20it%0A%20%20%20%20with%20the%20arguments%20the%20other%20way%20round%20and%20see%20that%20nothing%20stops%20you.%0A%20%20%20%20%22%22%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%23%20%60return%60%20sends%20a%20value%20back.%20%60print%60%20puts%20it%20on%20the%20screen%0A%0A%20%20%20%20They%20look%20the%20same%20in%20a%20notebook%20and%20they%20are%20not%20the%20same%20at%20all.%20A%20function%20that%0A%20%20%20%20prints%20has%20no%20**return%20value**%2C%20so%20it%20gives%20you%20%60None%60%2C%20and%20%60None%60%20is%20what%20the%20next%0A%20%20%20%20calculation%20receives.%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%20def%20shows_the_total(qty%2C%20price)%3A%0A%20%20%20%20%20%20%20%20print(qty%20*%20price)%0A%0A%20%20%20%20captured%20%3D%20shows_the_total(12%2C%2014.00)%0A%20%20%20%20captured%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%20The%20168.0%20above%20is%20the%20%60print%60%20firing.%20The%20cell's%20own%20value%20is%20%60None%60%2C%20and%20nothing%0A%20%20%20%20warned%20you.%0A%0A%20%20%20%20**The%20trap.**%20This%20is%20the%20most%20common%20mistake%20in%20agent-written%20code%2C%20and%20it%20is%20silent.%0A%20%20%20%20The%20function%20looks%20right%2C%20the%20notebook%20shows%20the%20number%2C%20and%20the%20total%20three%20cells%0A%20%20%20%20later%20is%20%60None%60.%0A%0A%20%20%20%20%F0%9F%91%89%20**Try%20it%3A**%20write%20%60captured%20*%202%60%20in%20a%20new%20cell%20and%20read%20the%20error.%20That%20is%20the%20error%0A%20%20%20%20you%20would%20actually%20meet%2C%20three%20cells%20away%20from%20the%20cause.%0A%20%20%20%20%22%22%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%23%20A%20parameter%20can%20have%20a%20default%0A%0A%20%20%20%20Give%20a%20parameter%20a%20value%20in%20the%20definition%2C%20a%20**default%20argument**%2C%20and%20the%20caller%20may%0A%20%20%20%20leave%20it%20out.%20Put%20the%20ones%20with%20defaults%20last.%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%20def%20order_amount(goods%2C%20freight_charge%3D0.0)%3A%0A%20%20%20%20%20%20%20%20return%20goods%20%2B%20freight_charge%0A%0A%20%20%20%20order_amount(440.00)%2C%20order_amount(440.00%2C%2016.75)%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%F0%9F%91%89%20**Try%20it%3A**%20call%20it%20with%20%60freight_charge%3D16.75%60%20written%20out.%0A%20%20%20%20That%20is%20a%20**keyword%20argument**%2C%20and%20naming%20it%20at%20the%20call%20site%20costs%20four%20seconds%20and%0A%20%20%20%20tells%20the%20next%20reader%20what%2016.75%20is.%0A%0A%20%20%20%20**The%20trap%2C%20and%20it%20is%20a%20real%20one%20from%20a%20real%20course.**%20A%20default%20of%20%606.25%60%20for%20a%20tax%0A%20%20%20%20rate%2C%20used%20as%20%60amount%20*%20rate%60%2C%20gives%20you%20625%20percent%20tax.%20The%20function%20runs%2C%20returns%20a%0A%20%20%20%20number%2C%20and%20the%20number%20is%20wrong%20by%20a%20factor%20of%20100.%20**A%20default%20is%20a%20decision%20you%20made%0A%20%20%20%20once%20and%20will%20not%20see%20again**%2C%20so%20write%20the%20units%20into%20the%20name%3A%20%60rate_percentage%60%2C%20not%20%60rate%60.%0A%20%20%20%20%22%22%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%23%20A%20name%20made%20inside%20a%20function%20does%20not%20exist%20outside%20it%0A%0A%20%20%20%20The%20parameters%20and%20anything%20you%20create%20in%20the%20body%20are%20gone%20when%20the%20function%20returns.%0A%20%20%20%20Those%20names%20are%20local%20to%20the%20function%2C%20which%20is%20what%20**scope**%20means.%20That%20is%20a%0A%20%20%20%20feature%3A%20it%20means%20a%20function%20cannot%20quietly%20change%20something%20you%20were%20using.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(line_amount)%3A%0A%20%20%20%20def%20order_lines_total()%3A%0A%20%20%20%20%20%20%20%20subtotal%20%3D%20line_amount(12%2C%2014.00)%20%2B%20line_amount(5%2C%2034.80)%20%2B%20line_amount(10%2C%209.80)%0A%20%20%20%20%20%20%20%20return%20subtotal%0A%0A%20%20%20%20order_lines_total()%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%20440.00%2C%20which%20is%20order%20%6010248%60%20before%20freight.%0A%0A%20%20%20%20%F0%9F%91%89%20**Try%20it%3A**%20add%20a%20cell%20with%20just%20%60subtotal%60%20in%20it%20and%20read%20the%20error.%20The%20name%20was%0A%20%20%20%20real%2C%20it%20did%20its%20job%2C%20and%20it%20is%20gone.%0A%20%20%20%20%22%22%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%23%20A%20**docstring**%20says%20what%20the%20function%20is%20for%0A%0A%20%20%20%20A%20string%20on%20the%20first%20line%20of%20the%20body%20is%20the%20function's%20**docstring**.%20It%20is%20not%20a%0A%20%20%20%20comment%3A%20Python%20keeps%20it%2C%20%60help()%60%20prints%20it%2C%20and%20your%20editor%20shows%20it%20when%20you%20hover%0A%20%20%20%20the%20name.%20Every%20%60help()%60%20you%20have%20ever%20read%20was%20somebody%20else's%20docstring.%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%20def%20order_amount_with_tax(goods%2C%20freight_charge%3D0.0%2C%20rate_percentage%3D7.0)%3A%0A%20%20%20%20%20%20%20%20%22%22%22Total%20for%20one%20order%2C%20in%20dollars.%0A%0A%20%20%20%20%20%20%20%20Assumes%20one%20row%20per%20order%2C%20and%20a%20rate%20in%20percent%2C%20not%20a%20fraction.%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20%20%20%20%20return%20(goods%20%2B%20freight_charge)%20*%20(1%20%2B%20rate_percentage%20%2F%20100)%0A%0A%20%20%20%20help(order_amount_with_tax)%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**Write%20the%20assumption%2C%20not%20the%20obvious.**%20A%20docstring%20reading%20*%22Adds%20the%20numbers%22*%0A%20%20%20%20repeats%20the%20code.%0A%20%20%20%20*%22Assumes%20one%20row%20per%20order%22*%20and%20*%22a%20rate%20in%20percent%2C%20not%20a%20fraction%22*%20are%20the%20two%0A%20%20%20%20things%20a%20reader%20cannot%20see%20and%20the%20two%20that%20go%20wrong%2C%20and%20the%20second%20one%20is%20the%20625%0A%20%20%20%20percent%20tax%20from%20a%20moment%20ago%2C%20written%20down%20where%20it%20can%20be%20checked.%0A%0A%20%20%20%20**This%20is%20also%20the%20one%20place%20your%20agent%20reads%20before%20it%20uses%20your%20function.**%20It%20gets%0A%20%20%20%20the%20docstring%20along%20with%20the%20code%2C%20so%20a%20sentence%20naming%20the%20grain%20your%20function%20expects%0A%20%20%20%20is%20how%20it%20stops%20handing%20you%20a%20total%20computed%20at%20the%20wrong%20one.%20Cheap%20insurance%20in%20both%0A%20%20%20%20directions%3A%20the%20reader%20is%20sometimes%20the%20agent%2C%20and%20sometimes%20you%20in%20November.%0A%0A%20%20%20%20%F0%9F%91%89%20**Try%20it%3A**%20delete%20the%20second%20line%20of%20the%20docstring%2C%20run%20%60help()%60%20again%2C%20and%20read%0A%20%20%20%20what%20a%20reader%20would%20now%20have%20to%20guess.%0A%0A%20%20%20%20%23%23%23%20%E2%9C%94%20Check%20your%20understanding%0A%0A%20%20%20%201.%20A%20function%20computes%20the%20right%20number%2C%20prints%20it%2C%20and%20has%20no%20%60return%60.%20What%20does%20the%0A%20%20%20%20%20%20%20caller%20get%3F%0A%20%20%20%202.%20Why%20write%20%60order_amount(440.00%2C%20freight_charge%3D16.75)%60%20when%0A%20%20%20%20%20%20%20%60order_amount(440.00%2C%2016.75)%60%20does%20the%20same%20thing%3F%0A%20%20%20%203.%20You%20define%20%60subtotal%60%20inside%20a%20function%20and%20use%20it%20outside.%20What%20happens%2C%20and%20why%20is%0A%20%20%20%20%20%20%20that%20the%20behavior%20you%20want%3F%0A%20%20%20%204.%20Your%20function%20returns%20a%20total%20and%20its%20docstring%20says%20*%22Adds%20the%20numbers%22*.%20Name%20one%0A%20%20%20%20%20%20%20thing%20a%20reader%20still%20cannot%20check%2C%20and%20write%20the%20sentence%20that%20would%20let%20them.%0A%20%20%20%20%22%22%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---%0A%20%20%20%20%23%23%209.%20Modules%20and%20%60import%60%0A%0A%20%20%20%20A%20**module**%20is%20a%20file%20of%20code%20somebody%20already%20wrote%2C%20and%20a%20**package**%20is%20a%20folder%20of%0A%20%20%20%20them%20that%20you%20install.%20%60import%60%20is%20how%20you%20reach%20either.%20Every%20line%20of%20Python%20you%20will%0A%20%20%20%20read%20outside%20this%20course%20starts%20with%20a%20few%20of%20them%2C%20and%20the%20three%20ways%20of%20writing%20one%0A%20%20%20%20are%20not%20interchangeable.%0A%0A%20%20%20%20%F0%9F%93%96%20**Used%20in%3A**%20Reading%20an%20error%20message%20%C2%B7%20Building%20and%20querying%20your%20database%0A%20%20%20%20%22%22%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%23%20%60import%20X%60%0A%0A%20%20%20%20Python%20ships%20with%20a%20large%20standard%20library.%20Nothing%20is%20installed%20here%3B%20%60math%60%20came%20with%0A%20%20%20%20the%20language.%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%20import%20math%0A%0A%20%20%20%20cases_needed%20%3D%20math.ceil(17%20%2F%205)%0A%20%20%20%20cases_needed%2C%20math.pi%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%20Seventeen%20units%2C%20five%20to%20a%20case%2C%20four%20cases.%20%60math.pi%60%20is%20an%20**attribute**%2C%20a%20value%20you%0A%20%20%20%20reach%20the%20same%20way.%0A%0A%20%20%20%20%F0%9F%91%89%20**Try%20it%3A**%20run%20%60math%60%20on%20its%20own%20line%2C%20then%20%60import%20json%60%20and%20%60json%60.%20%60math%60%20says%0A%20%20%20%20%60built-in%60%2C%20because%20it%20is%20compiled%20into%20Python%3B%20%60json%60%20names%20the%20file%20it%20came%20from.%0A%20%20%20%20%22%22%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%23%20%60from%20X%20import%20Y%60%0A%0A%20%20%20%20Same%20module%2C%20different%20import%2C%20different%20call.%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%20from%20statistics%20import%20mean%0A%0A%20%20%20%20mean(%5B16.75%2C%2022.25%2C%2025.00%2C%2020.25%2C%2036.25%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%20That%20is%20the%20average%20freight%20on%20orders%20%6010248%60%20to%20%6010252%60.%0A%0A%20%20%20%20The%20square%20brackets%20make%20a%20**list**%2C%20which%20is%20Chapter%20B's%20subject.%20It%20is%20the%20one%20place%0A%20%20%20%20this%20chapter%20needs%20one%2C%20because%20handing%20%60mean%60%20five%20numbers%20at%20once%20is%20what%20it%20is%20for.%0A%0A%20%20%20%20**Which%20to%20use.**%20%60import%20X%60%20keeps%20the%20module's%20name%20in%20front%20of%20every%20call%2C%20so%20a%0A%20%20%20%20reader%20can%20see%20where%20%60ceil%60%20came%20from.%20%60from%20X%20import%20Y%60%20is%20shorter%20and%20loses%20that.%0A%20%20%20%20Prefer%20the%20first%20for%20anything%20unfamiliar.%0A%0A%20%20%20%20%F0%9F%91%89%20**Try%20it%3A**%20write%20%60statistics.mean(...)%60%20after%20that%20import%20and%20read%20the%20error.%0A%20%20%20%20Importing%20one%20name%20does%20not%20bring%20the%20module%20in%20with%20it.%0A%20%20%20%20%22%22%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%23%20%60import%20X%20as%20Y%60%0A%0A%20%20%20%20The%20short%20name%20is%20an%20**alias**.%20Nobody%20writes%20%60polars.DataFrame%60%3B%20everybody%20writes%0A%20%20%20%20%60pl.DataFrame%60%2C%20as%20pandas%20code%20writes%20%60pd.DataFrame%60%2C%20and%20the%20reason%20is%20one%20line%20at%20the%0A%20%20%20%20top%20of%20the%20file%20that%20most%20tutorials%20never%20explain.%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%20import%20statistics%20as%20stats%0A%0A%20%20%20%20stats.median(%5B16.75%2C%2022.25%2C%2025.00%2C%2020.25%2C%2036.25%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%F0%9F%91%89%20**Try%20it%3A**%20the%20mean%20of%20those%20five%20is%2024.10%20and%20the%20median%20is%2022.25.%20Which%20one%20would%0A%20%20%20%20you%20put%20in%20a%20sentence%20about%20typical%20freight%2C%20and%20what%20would%20the%20other%20one%20let%20somebody%0A%20%20%20%20argue%3F%0A%20%20%20%20%22%22%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%23%20A%20file%20you%20wrote%20is%20a%20module%20too%0A%0A%20%20%20%20Put%20a%20function%20in%20a%20file%20next%20to%20your%20notebook%20and%20import%20it%20by%20the%20file's%20name%20without%0A%20%20%20%20%60.py%60.%20This%20is%20how%20a%20calculation%20stops%20being%20copied%20into%20four%20notebooks.%0A%0A%20%20%20%20%60%60%60python%0A%20%20%20%20%23%20orders.py%2C%20sitting%20beside%20your%20notebook%0A%20%20%20%20def%20line_amount(qty%2C%20price)%3A%0A%20%20%20%20%20%20%20%20return%20qty%20*%20price%0A%20%20%20%20%60%60%60%0A%0A%20%20%20%20%60%60%60python%0A%20%20%20%20%23%20in%20the%20notebook%0A%20%20%20%20from%20orders%20import%20line_amount%0A%20%20%20%20%60%60%60%0A%0A%20%20%20%20**The%20trap.**%20Python%20looks%20for%20%60orders.py%60%20**in%20the%20folder%20you%20started%20from**.%20That%20is%20the%0A%20%20%20%20same%20folder%20the%20notebook%20sits%20in%20only%20if%20you%20opened%20the%20project%20the%20way%20this%20course%0A%20%20%20%20tells%20you%20to.%20When%20it%20is%20not%20found%20you%20get%20a%20%60ModuleNotFoundError%60%2C%20and%0A%20%20%20%20%C2%A710%20is%20about%20reading%20it.%0A%0A%20%20%20%20**The%20second%20trap.**%20Importing%20a%20file%20**runs%20everything%20in%20it**.%20A%20file%20with%0A%20%20%20%20%60print(line_amount(12%2C%2014.00))%60%20at%20the%20bottom%20prints%20168.0%20the%20moment%20anybody%20imports%0A%20%20%20%20it.%20Keep%20files%20you%20import%20to%20definitions.%0A%20%20%20%20%22%22%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%F0%9F%91%89%20**Try%20it%3A**%20make%20%60orders.py%60%20beside%20your%20notebook%20with%20that%20one%20function%20in%20it%2C%0A%20%20%20%20import%20it%2C%20and%20call%20it.%20Then%20add%20a%20%60print(...)%60%20line%20at%20the%20bottom%20of%20%60orders.py%60%20and%0A%20%20%20%20import%20it%20again%20in%20a%20fresh%20cell.%0A%0A%20%20%20%20%23%23%23%20%E2%9C%94%20Check%20your%20understanding%0A%0A%20%20%20%201.%20After%20%60from%20statistics%20import%20mean%60%2C%20does%20%60statistics.median(...)%60%20work%3F%20Why%3F%0A%20%20%20%202.%20You%20write%20%60import%20polars%20as%20pl%60.%20What%20have%20you%20actually%20changed%3F%0A%20%20%20%203.%20Your%20own%20%60orders.py%60%20sits%20beside%20the%20notebook%20and%20the%20import%20still%20fails.%20Name%20the%0A%20%20%20%20%20%20%20first%20thing%20to%20check.%0A%20%20%20%20%22%22%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---%0A%20%20%20%20%23%23%2010.%20Reading%20a%20traceback%0A%0A%20%20%20%20When%20Python%20cannot%20finish%20running%20your%20code%20it%20stops%20and%20prints%20a%20**traceback**%3A%20a%0A%20%20%20%20block%20of%20red%20text%2C%20several%20lines%20long%2C%20ending%20in%20the%20name%20of%20what%20went%20wrong.%20It%0A%20%20%20%20looks%20like%20a%20wall.%20It%20is%20a%20list%2C%20and%20it%20has%20a%20shape.%0A%0A%20%20%20%20%F0%9F%93%96%20**Used%20in%3A**%20Reading%20an%20error%20message%0A%20%20%20%20%22%22%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%23%20Reading%20a%20traceback%0A%0A%20%20%20%20%60%60%60python%0A%20%20%20%20customer%20%3D%20%22Alfreds%20Futterkiste%22%0A%20%20%20%20print(customer%5B50%5D)%0A%20%20%20%20%60%60%60%0A%0A%20%20%20%20%60%60%60%0A%20%20%20%20Traceback%20(most%20recent%20call%20last)%3A%0A%20%20%20%20%20%20File%20%22orders.py%22%2C%20line%202%2C%20in%20%3Cmodule%3E%0A%20%20%20%20%20%20%20%20print(customer%5B50%5D)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20~~~~~~~~%5E%5E%5E%5E%0A%20%20%20%20IndexError%3A%20string%20index%20out%20of%20range%0A%20%20%20%20%60%60%60%0A%0A%20%20%20%20-%20**%60Traceback%20(most%20recent%20call%20last)%60**%20is%20a%20header.%20It%20never%20changes.%0A%20%20%20%20-%20**The%20indented%20block**%20is%20the%20route%20Python%20took%20to%20get%20there.%20When%20your%20code%20calls%0A%20%20%20%20%20%20something%20that%20calls%20something%20else%2C%20there%20is%20one%20of%20these%20per%20step%2C%20oldest%20first.%0A%20%20%20%20-%20**The%20last%20line**%20names%20what%20went%20wrong.%20%60IndexError%60%20is%20the%20kind%20of%20problem%2C%20and%20an%0A%20%20%20%20%20%20error%20Python%20raises%20this%20way%20is%20an%20**exception**.%20%60string%20index%20out%20of%20range%60%20is%20the%0A%20%20%20%20%20%20detail.%0A%0A%20%20%20%20**Read%20the%20last%20line%20first.**%20The%20lines%20above%20it%20show%20how%20Python%20got%20there.%0A%20%20%20%20%22%22%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%F0%9F%91%89%20**Try%20it%3A**%20run%20those%20two%20lines%20in%20a%20cell.%20Then%20change%2050%20to%205%20and%20run%20again.%0A%20%20%20%20%22%22%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%23%20When%20a%20%60SyntaxError%60%20happens%0A%0A%20%20%20%20The%20other%20three%20errors%20happen%20while%20your%20code%20runs.%20A%20%60SyntaxError%60%20happens%20before%0A%20%20%20%20any%20of%20it%20runs%2C%20because%20Python%20could%20not%20read%20the%20file%20at%20all.%20Nothing%20in%20the%20cell%0A%20%20%20%20executed%2C%20which%20is%20why%20fixing%20one%20often%20fixes%20several%20complaints%20at%20once.%0A%0A%20%20%20%20%60%60%60python%0A%20%20%20%20freight_charges%20%3D%20(16.75%2C%2022.25%0A%20%20%20%20print(freight_charges)%0A%20%20%20%20%60%60%60%0A%0A%20%20%20%20%60%60%60%0A%20%20%20%20%20%20File%20%22orders.py%22%2C%20line%201%0A%20%20%20%20%20%20%20%20freight_charges%20%3D%20(16.75%2C%2022.25%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%5E%0A%20%20%20%20SyntaxError%3A%20'('%20was%20never%20closed%0A%20%20%20%20%60%60%60%0A%0A%20%20%20%20**Modern%20Python%20is%20good%20at%20this%20one.**%20It%20names%20the%20bracket%2C%20points%20at%20it%2C%20and%20gives%0A%20%20%20%20the%20line%20it%20was%20opened%20on.%20An%20unterminated%20quote%20reads%20the%20same%20way%3A%0A%20%20%20%20%60unterminated%20string%20literal%20(detected%20at%20line%201)%60.%0A%0A%20%20%20%20Older%20tutorials%20and%20older%20answers%20on%20the%20web%20show%20a%20bare%20%60SyntaxError%3A%20invalid%0A%20%20%20%20syntax%60%20blaming%20the%20line%20*after*%20the%20mistake%2C%20because%20that%20is%20what%20Python%20did%20before%0A%20%20%20%203.10.%20If%20you%20meet%20that%20message%2C%20the%20fix%20is%20to%20look%20one%20line%20up.%20On%20the%20Python%20this%0A%20%20%20%20course%20installs%20you%20will%20usually%20get%20the%20better%20one.%0A%20%20%20%20%22%22%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%F0%9F%91%89%20**Try%20it%3A**%20delete%20a%20closing%20quote%20somewhere%20and%20read%20what%20it%20says.%20Then%20delete%20a%0A%20%20%20%20closing%20bracket.%20In%20both%2C%20the%20caret%20under%20the%20line%20marks%20the%20character%20left%20open.%0A%20%20%20%20%22%22%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%23%20The%20errors%20you%20will%20meet%20most%0A%0A%20%20%20%20%7C%20what%20it%20says%20%7C%20what%20it%20usually%20means%20%7C%0A%20%20%20%20%7C---%7C---%7C%0A%20%20%20%20%7C%20%60ModuleNotFoundError%60%20%7C%20the%20package%20is%20not%20installed%20in%20this%20environment%2C%20or%20the%20name%20is%20misspelled%20%7C%0A%20%20%20%20%7C%20%60FileNotFoundError%60%20%7C%20the%20file%20is%20not%20where%20the%20code%20thinks%20it%20is.%20Check%20which%20folder%20you%20are%20in%20%7C%0A%20%20%20%20%7C%20%60NameError%60%20%7C%20you%20used%20a%20name%20before%20anything%20put%20a%20value%20in%20it%2C%20or%20you%20misspelled%20it%20%7C%0A%20%20%20%20%7C%20%60SyntaxError%60%20%7C%20Python%20could%20not%20read%20the%20code%2C%20so%20none%20of%20it%20ran.%20The%20caret%20under%20the%20line%20marks%20where%20it%20stopped%20%7C%0A%0A%20%20%20%20%F0%9F%91%89%20**Try%20it%3A**%20cause%20each%20of%20the%20four%20on%20purpose%2C%20one%20per%20cell.%20%60import%20pandsa%60%3B%0A%20%20%20%20%60open(%22sales.csv%22)%60%3B%20%60print(totl)%60%3B%20a%20bracket%20you%20never%20close.%20Read%20the%20last%20line%20of%0A%20%20%20%20each%20before%20you%20fix%20it.%0A%20%20%20%20%22%22%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%23%20%E2%9C%94%20Check%20your%20understanding%0A%0A%20%20%20%201.%20A%20traceback%20is%2011%20lines%20long.%20Which%20line%20tells%20you%20what%20went%20wrong%3F%0A%20%20%20%202.%20Your%20code%20says%20%60import%20pandas%60%20and%20you%20get%20a%20%60ModuleNotFoundError%60.%20Name%20two%0A%20%20%20%20%20%20%20different%20reasons%20that%20could%20happen.%0A%20%20%20%203.%20A%20%60SyntaxError%60%20and%20a%20%60NameError%60%20in%20the%20same%20cell.%20Which%20one%20happened%20first%2C%20and%0A%20%20%20%20%20%20%20how%20do%20you%20know%20without%20running%20anything%3F%0A%20%20%20%20%22%22%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---%0A%20%20%20%20%23%23%20Chapter%20challenge%0A%0A%20%20%20%20**Write%20the%20shipping%20line.**%20Nothing%20here%20is%20due.%20It%20exists%20because%20the%20sections%20above%20each%20teach%20one%20thing%20and%0A%20%20%20%20a%20real%20line%20of%20work%20needs%20all%20of%20them%20at%20once.%0A%0A%20%20%20%20**Build%20one%20sentence%20a%20colleague%20would%20accept**%2C%20from%20these%20four%20facts%20and%20nothing%20else%3A%0A%0A%20%20%20%20-%20a%20customer%20name%2C%20typed%20by%20a%20person%2C%20with%20stray%20spaces%20and%20inconsistent%20case%0A%20%20%20%20-%20an%20order%20value%0A%20%20%20%20-%20a%20freight%20charge%0A%20%20%20%20-%20a%20country%0A%0A%20%20%20%20The%20sentence%20has%20to%20say%20who%20ordered%2C%20what%20it%20came%20to%2C%20what%20shipping%20cost%2C%20and%20whether%0A%20%20%20%20this%20order%20qualifies%20for%20free%20shipping.%20Format%20the%20money%20properly.%0A%0A%20%20%20%20**Three%20decisions%20are%20yours%2C%20and%20the%20notebook%20cannot%20make%20them.**%0A%0A%20%20%20%201.%20What%20is%20the%20free%20shipping%20threshold%2C%20and%20is%20it%20%60%3E%60%20or%20%60%3E%3D%60%3F%20Write%20the%20operator%20you%0A%20%20%20%20%20%20%20mean.%0A%20%20%20%202.%20What%20does%20the%20sentence%20say%20when%20the%20freight%20charge%20is%200%3F%20Free%20shipping%20and%20no%0A%20%20%20%20%20%20%20shipping%20are%20different%20things.%0A%20%20%20%203.%20Does%20the%20customer%20name%20appear%20as%20typed%2C%20or%20cleaned%20up%3F%20Explain%20why.%0A%0A%20%20%20%20**Done%20looks%20like**%20one%20cell%20that%20produces%20one%20sentence%2C%20plus%20a%20markdown%20cell%20naming%0A%20%20%20%20the%20three%20decisions%20you%20made%20and%20what%20the%20alternative%20would%20have%20been.%0A%0A%20%20%20%20**Going%20further.**%20Take%20the%20order%20value%20in%20as%20text%2C%20the%20way%20a%20form%20would%20hand%20it%20to%0A%20%20%20%20you%2C%20and%20make%20it%20work.%20Then%20make%20it%20survive%20a%20value%20of%20%60%221%2C240.00%22%60%20with%20the%20comma%0A%20%20%20%20in%20it.%20Then%20decide%20what%20should%20happen%20when%20somebody%20passes%20%60%22n%2Fa%22%60%2C%20and%20defend%20the%0A%20%20%20%20answer.%0A%20%20%20%20%22%22%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---%0A%20%20%20%20%23%23%20%F0%9F%A4%96%20Ask%20your%20agent%0A%0A%20%20%20%20Two%20different%20uses%2C%20and%20the%20second%20one%20is%20the%20one%20this%20course%20grades.%0A%0A%20%20%20%20%23%23%23%20Ask%20it%20about%20what%20this%20chapter%20left%20out%0A%0A%20%20%20%20Every%20one%20of%20these%20is%20real%20Python%20that%20had%20no%20room%20above.%0A%0A%20%20%20%20-%20%607%20%5E%202%60%20gives%205%2C%20which%20is%20not%2049.%20Ask%20what%20the%20bitwise%20operators%20are%20and%20what%20%60%5E%60%0A%20%20%20%20%20%20does%20to%20two%20integers.%0A%20%20%20%20-%20%60round()%60%20takes%20a%20second%20argument.%20Ask%20how%20to%20round%20pi%20to%20three%20decimal%20places.%0A%20%20%20%20-%20Python%20lets%20you%20write%20%600%20%3C%20order_value%20%3C%20100%60.%20Ask%20whether%20other%20languages%20do%2C%20and%0A%20%20%20%20%20%20what%20it%20means.%0A%20%20%20%20-%20Ask%20what%20%60f%22%7Bfreight%3D%7D%22%60%20prints%2C%20and%20when%20that%20form%20is%20useful.%0A%20%20%20%20-%20Ask%20what%20%60divmod(17%2C%205)%60%20returns%20and%20how%20it%20relates%20to%20%60%2F%2F%60%20and%20%60%25%60.%0A%0A%20%20%20%20Test%20whatever%20it%20gives%20you.%20Paste%20it%20into%20a%20cell%20and%20run%20it.%0A%0A%20%20%20%20%23%23%23%20Watch%20what%20it%20decides%20without%20telling%20you%0A%0A%20%20%20%20Give%20it%20this%2C%20exactly%3A%0A%0A%20%20%20%20%3E%20*%22Write%20Python%20that%20tiers%20an%20order%20value%20into%20A%2C%20B%20or%20C.%22*%0A%0A%20%20%20%20Then%20read%20what%20came%20back%20and%20answer%20three%20questions.%0A%0A%20%20%20%201.%20**What%20are%20the%20thresholds%3F**%20You%20did%20not%20give%20any.%0A%20%20%20%202.%20**Is%20each%20boundary%20%60%3E%60%20or%20%60%3E%3D%60%3F**%20Read%20the%20operators.%20Ignore%20the%20prose%20around%20them.%0A%20%20%20%203.%20**What%20happens%20to%20a%20negative%20order%20value%2C%20or%20to%20text%3F**%0A%0A%20%20%20%20You%20asked%20for%20one%20thing%20and%20got%20four%20or%20five%20decisions.%20That%20gap%20is%20the%20subject%20of%0A%20%20%20%20this%20course%2C%20and%20it%20does%20not%20go%20away%20as%20the%20models%20get%20better.%20It%20gets%20quieter.%0A%0A%20%20%20%20%F0%9F%91%89%20**Try%20it%3A**%20send%20the%20same%20sentence%20twice%2C%20in%20two%20separate%20conversations.%20Compare%20the%0A%20%20%20%20thresholds.%0A%20%20%20%20%22%22%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---%0A%20%20%20%20%23%23%20Chapter%20A%20checklist%0A%0A%20%20%20%20-%20%5B%20%5D%20I%20can%20put%20a%20value%20in%20a%20name%20and%20use%20it%20somewhere%20else%0A%20%20%20%20-%20%5B%20%5D%20I%20can%20name%20the%20four%20types%20I%20will%20meet%20constantly%2C%20and%20ask%20what%20type%20a%20value%20has%0A%20%20%20%20-%20%5B%20%5D%20I%20can%20predict%20what%20%60%225%22%20%2B%20%223%22%60%20gives%2C%20and%20what%20%605%20%2B%20%223%22%60%20gives%0A%20%20%20%20-%20%5B%20%5D%20I%20can%20convert%20text%20to%20a%20number%20and%20know%20why%20I%20had%20to%0A%20%20%20%20-%20%5B%20%5D%20I%20know%20which%20operator%20runs%20first%2C%20and%20I%20use%20parentheses%20when%20I%20am%20not%20sure%0A%20%20%20%20-%20%5B%20%5D%20I%20can%20write%20a%20comparison%20and%20read%20the%20%60True%60%20or%20%60False%60%20it%20produces%0A%20%20%20%20-%20%5B%20%5D%20I%20can%20write%20an%20%60if%60%20chain%20and%20predict%20which%20branch%20a%20given%20value%20lands%20in%0A%20%20%20%20-%20%5B%20%5D%20I%20can%20spot%20a%20boundary%20decision%20hidden%20in%20%60%3E%3D%60%20against%20%60%3E%60%0A%20%20%20%20-%20%5B%20%5D%20I%20can%20take%20a%20piece%20out%20of%20a%20string%2C%20clean%20it%2C%20and%20keep%20the%20result%0A%20%20%20%20-%20%5B%20%5D%20I%20can%20print%20a%20sentence%20with%20a%20formatted%20number%20in%20it%0A%20%20%20%20-%20%5B%20%5D%20I%20can%20turn%20a%20piece%20of%20text%20into%20a%20real%20date%2C%20and%20explain%20why%20that%20matters%0A%20%20%20%20-%20%5B%20%5D%20I%20can%20subtract%20two%20dates%20and%20get%20a%20number%20of%20days%20out%20of%20the%20result%0A%20%20%20%20-%20%5B%20%5D%20I%20know%20why%20a%20timestamp%20does%20not%20equal%20the%20date%20it%20falls%20on%0A%20%20%20%20-%20%5B%20%5D%20I%20can%20write%20a%20function%20with%20parameters%20and%20a%20%60return%60%0A%20%20%20%20-%20%5B%20%5D%20I%20can%20state%20what%20a%20function%20that%20forgets%20to%20return%20gives%20back%0A%20%20%20%20-%20%5B%20%5D%20I%20can%20give%20a%20parameter%20a%20default%2C%20and%20I%20write%20the%20units%20into%20its%20name%0A%20%20%20%20-%20%5B%20%5D%20I%20can%20read%20%60import%20x%60%2C%20%60from%20x%20import%20y%60%20and%20%60import%20x%20as%20y%60%20and%20explain%20what%20each%20did%0A%20%20%20%20-%20%5B%20%5D%20I%20can%20put%20a%20function%20in%20a%20file%20of%20my%20own%20and%20import%20it%0A%20%20%20%20-%20%5B%20%5D%20I%20can%20read%20a%20traceback%20and%20name%20the%20line%20at%20fault%0A%0A%20%20%20%20**Chapter%20B%20is%20Collections**%3A%20a%20name%20holding%20several%20things%20at%20once%2C%20and%20the%20shape%0A%20%20%20%20you%20choose%20for%20a%20table.%0A%20%20%20%20%22%22%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
d1e1db25de4eb6d4278a899a5c73448d