import%20marimo%0A%0A__generated_with%20%3D%20%220.23.13%22%0Aapp%20%3D%20marimo.App()%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%20Python%20Basics%0A%0A%20%20%20%20This%20lesson%20covers%20the%20fundamentals%20of%20the%20Python%20language%3A%20variables%2C%20data%20types%2C%20collections%2C%20control%20flow%2C%20and%20functions.%20These%20are%20the%20building%20blocks%20used%20throughout%20the%20later%20lessons.%0A%0A%20%20%20%20%23%23%23%20Comments%0A%0A%20%20%20%20Comments%20start%20with%20%60%23%60%20and%20are%20ignored%20by%20Python.%20Use%20them%20to%20explain%20what%20your%20code%20does.%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%20%23%20This%20is%20a%20comment%0A%20%20%20%20print(%22Hello%2C%20World!%22)%20%20%23%20Print%20a%20greeting%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%20Multiline%20comments%20use%20triple%20quotes%3A%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%20%22%22%22%0A%20%20%20%20This%20is%20a%20multiline%20comment.%0A%20%20%20%20It%20can%20span%20multiple%20lines.%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%20Variables%0A%0A%20%20%20%20Variables%20act%20as%20labelled%20containers%20for%20data.%20Assign%20values%20using%20%60%3D%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%20%23%20Assigning%20values%20to%20variables%0A%20%20%20%20message%20%3D%20%22Hello%2C%20Python!%22%20%20%23%20Text%20(string)%0A%20%20%20%20count%20%3D%2010%20%20%23%20Whole%20number%20(integer)%0A%20%20%20%20price%20%3D%2019.99%20%20%23%20Decimal%20number%20(float)%0A%20%20%20%20is_active%20%3D%20False%20%20%23%20True%2FFalse%20value%20(boolean)%0A%0A%20%20%20%20%23%20Accessing%20variable%20values%0A%20%20%20%20print(message)%0A%20%20%20%20print(count)%0A%20%20%20%20print(price)%0A%20%20%20%20print(is_active)%0A%20%20%20%20return%20count%2C%20is_active%2C%20message%2C%20price%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%20Data%20Types%0A%0A%20%20%20%20Variables%20can%20hold%20different%20types%20of%20data%2C%20such%20as%20numbers%20(integers%20or%20floats)%20and%20text%20(strings).%20The%20functionality%20available%20often%20depends%20on%20the%20data%20type%2C%20though%20some%20behaviours%20are%20shared%20across%20types.%0A%0A%20%20%20%20-%20**%60str%60%20(String)%3A**%20Text%2C%20enclosed%20in%20quotes%20(%60%22%60%20or%20%60'%60).%20Example%3A%20%60%22Urbanism%22%60.%0A%20%20%20%20-%20**%60int%60%20(Integer)%3A**%20Whole%20numbers.%20Example%3A%20%6042%60%2C%20%60-7%60.%0A%20%20%20%20-%20**%60float%60%20(Float)%3A**%20Numbers%20with%20decimals.%20Example%3A%20%603.14%60%2C%20%60-0.001%60.%0A%20%20%20%20-%20**%60bool%60%20(Boolean)%3A**%20Logical%20values%2C%20%60True%60%20or%20%60False%60%20(capitalised).%0A%0A%20%20%20%20Check%20a%20variable's%20type%20using%20%60type()%60%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(count%2C%20is_active%2C%20message%2C%20price)%3A%0A%20%20%20%20print(type(message))%20%20%23%20%3Cclass%20'str'%3E%0A%20%20%20%20print(type(count))%20%20%23%20%3Cclass%20'int'%3E%0A%20%20%20%20print(type(price))%20%20%23%20%3Cclass%20'float'%3E%0A%20%20%20%20print(type(is_active))%20%20%23%20%3Cclass%20'bool'%3E%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%20When%20working%20with%20variables%2C%20especially%20in%20Python%2C%20be%20cognisant%20of%20the%20type%20assigned%20to%20the%20variable.%20Misusing%20types%20can%20lead%20to%20issues%20and%20errors.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(count%2C%20message)%3A%0A%20%20%20%20%23%20This%20will%20raise%20an%20error%20because%20you%20cannot%20add%20a%20string%20to%20an%20integer%0A%20%20%20%20%23%20TypeError%3A%20unsupported%20operand%20type(s)%20for%20%2B%3A%20'int'%20and%20'str'%0A%0A%20%20%20%20count%20%2B%20message%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%20Python%20supports%20standard%20arithmetic%20operations%3A%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%20%23%20Arithmetic%20operators%3A%20%2B%2C%20-%2C%20*%2C%20%2F%2C%20**%2C%20%25%0A%20%20%20%20a%20%3D%2010%0A%20%20%20%20b%20%3D%203%0A%0A%20%20%20%20print(a%20%2B%20b)%20%20%23%20Addition%3A%2013%0A%20%20%20%20print(a%20-%20b)%20%20%23%20Subtraction%3A%207%0A%20%20%20%20print(a%20*%20b)%20%20%23%20Multiplication%3A%2030%0A%20%20%20%20print(a%20%2F%20b)%20%20%23%20Division%20(float%20result)%3A%203.333...%0A%20%20%20%20print(a**b)%20%20%23%20Exponentiation%3A%201000%0A%20%20%20%20print(a%20%25%20b)%20%20%23%20Modulus%20(remainder)%3A%201%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%20Python%20follows%20the%20standard%20order%20of%20operations%20(often%20remembered%20by%20acronyms%20like%20BODMAS%20or%20PEMDAS).%20For%20example%3A%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%20_result%20%3D%202%20%2B%203%20*%204%20-%205%20%2F%202%0A%20%20%20%20print(_result)%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%20If%20you're%20ever%20unsure%20about%20the%20order%2C%20it's%20good%20practice%20to%20use%20parentheses%20%60()%60%20to%20make%20your%20intention%20explicit.%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%20_result%20%3D%20(2%20%2B%203)%20*%204%20-%205%20%2F%202%0A%20%20%20%20print(_result)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20_result%20%3D%202%20%2B%203%20*%20(4%20-%205)%20%2F%202%0A%20%20%20%20print(_result)%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%0A%0A%20%20%20%20Strings%20are%20very%20versatile%20and%20have%20a%20number%20of%20built-in%20methods%20for%20common%20use%20cases.%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%20first_name%20%3D%20%22Ada%22%0A%20%20%20%20last_name%20%3D%20%22Lovelace%22%0A%20%20%20%20full_name%20%3D%20first_name%20%2B%20%22%20%22%20%2B%20last_name%0A%20%20%20%20print(full_name)%20%20%23%20Output%3A%20Ada%20Lovelace%0A%20%20%20%20return%20(full_name%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%3E%20**Note%3A**%0A%20%20%20%20%3E%20A%20method%20is%20like%20a%20function%20that's%20associated%20with%20a%20particular%20object%20or%20type%20(like%20a%20string).%20For%20example%2C%20%60str.upper()%60%20is%20a%20method%20of%20the%20%60str%60%20class%20that%20converts%20a%20string%20to%20uppercase.%20You%20access%20methods%20using%20dot%20notation%20(%60object.method()%60)%20and%20execute%20them%20by%20using%20parentheses.%20If%20a%20method%20requires%20options%20or%20parameters%2C%20they%20go%20inside%20the%20parentheses.%0A%0A%20%20%20%20Common%20built-in%20methods%20include%20converting%20text%20to%20lower%20or%20upper%20case%2C%20or%20removing%20leading%2Ftrailing%20whitespace%20and%20characters.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(full_name)%3A%0A%20%20%20%20%23%20String%20methods%0A%20%20%20%20print(full_name.lower())%20%20%23%20Lowercase%3A%20%22ada%20lovelace%22%0A%20%20%20%20print(full_name.upper())%20%20%23%20Uppercase%3A%20%22ADA%20LOVELACE%22%0A%20%20%20%20print(full_name.replace(%22%20%22%2C%20%22_%22))%20%20%23%20Replace%20spaces%20with%20underscores%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%23%20F-Strings%0A%0A%20%20%20%20F-strings%20(formatted%20string%20literals)%20offer%20a%20convenient%20way%20to%20embed%20expressions%20inside%20string%20literals%20for%20formatting.%20Simply%20prefix%20the%20string%20with%20an%20%60f%60%20and%20write%20expressions%20in%20%60%7B%7D%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%20city%20%3D%20%22Berlin%22%0A%20%20%20%20population%20%3D%203800000%0A%20%20%20%20info%20%3D%20f%22The%20city%20of%20%7Bcity%7D%20has%20a%20population%20of%20%7Bpopulation%7D.%22%0A%20%20%20%20print(info)%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%20Exercises%0A%0A%20%20%20%20-%20Create%20a%20variable%20for%20a%20number.%20Print%20its%20type%20using%20%60type()%60.%0A%20%20%20%20-%20Create%20a%20variable%20for%20your%20name%2C%20then%20print%20a%20statement%20using%20an%20F-string%20to%20say%20%22Hello%2C%20%5Byour%20name%5D!%22.%0A%20%20%20%20-%20Perform%20all%20basic%20arithmetic%20operations%20(%2B%2C%20-%2C%20%5C*%2C%20%2F%2C%20%25)%20on%20two%20numbers%20and%20print%20the%20results.%20Experiment%20with%20parentheses%20%60()%60%20to%20change%20the%20order%20of%20operations.%0A%0A%20%20%20%20%23%23%20Collections%0A%0A%20%20%20%20Often%2C%20you%20need%20to%20work%20with%20multiple%20pieces%20of%20data%20at%20once.%20Python%20provides%20several%20ways%20to%20group%20data%2C%20each%20with%20its%20own%20characteristics.%0A%0A%20%20%20%20%7C%20Type%20%20%20%20%20%20%20%7C%20Ordered%20%7C%20Unique%20%20%20%20%20%20%20%7C%20Mutable%20%7C%20Example%20Syntax%20%20%20%20%20%7C%20Example%20Use%20Case%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7C%0A%20%20%20%20%7C%20----------%20%7C%20-------%20%7C%20------------%20%7C%20-------%20%7C%20------------------%20%7C%20-----------------------------%20%7C%0A%20%20%20%20%7C%20List%20%20%20%20%20%20%20%7C%20Yes%20%20%20%20%20%7C%20No%20%20%20%20%20%20%20%20%20%20%20%7C%20Yes%20%20%20%20%20%7C%20%60%5B1%2C%202%2C%203%5D%60%20%20%20%20%20%20%20%20%7C%20Shopping%20list%2C%20coordinates%20%20%20%20%7C%0A%20%20%20%20%7C%20Tuple%20%20%20%20%20%20%7C%20Yes%20%20%20%20%20%7C%20No%20%20%20%20%20%20%20%20%20%20%20%7C%20No%20%20%20%20%20%20%7C%20%60(1%2C%202%2C%203)%60%20%20%20%20%20%20%20%20%7C%20Fixed%20coordinates%2C%20RGB%20colour%20%7C%0A%20%20%20%20%7C%20Set%20%20%20%20%20%20%20%20%7C%20No%20%20%20%20%20%20%7C%20Yes%20(Values)%20%7C%20Yes%20%20%20%20%20%7C%20%60%7B1%2C%202%2C%203%7D%60%20%20%20%20%20%20%20%20%7C%20Unique%20tags%2C%20deduplication%20%20%20%20%7C%0A%20%20%20%20%7C%20Dictionary%20%7C%20Yes%20%20%20%20%20%7C%20Yes%20(Keys)%20%20%20%7C%20Yes%20%20%20%20%20%7C%20%60%7B%22a%22%3A%201%2C%20%22b%22%3A%202%7D%60%20%7C%20Lookup%20tables%2C%20data%20records%20%20%20%7C%0A%0A%20%20%20%20%23%23%23%20Lists%0A%0A%20%20%20%20Use%20lists%20when%20the%20order%20of%20items%20is%20important%20and%20you%20might%20need%20to%20change%20them%20later.%20Lists%20are%20_mutable_%20(meaning%20they%20can%20be%20changed%20after%20creation).%20Think%20of%20them%20like%20a%20row%20of%20mailboxes%3A%20you%20can%20change%20what's%20inside%20a%20mailbox.%20Access%20items%20using%20their%20_index_%20(position%2C%20starting%20from%200)%20in%20square%20brackets%20%60%5B%5D%60.%20Negative%20indexing%20is%20also%20handy%2C%20where%20%60-1%60%20refers%20to%20the%20last%20item%2C%20%60-2%60%20to%20the%20second%20last%2C%20and%20so%20on.%0A%0A%20%20%20%20Create%20a%20list%20using%20square%20brackets%20%5B%5D%3A%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%20planets%20%3D%20%5B%22Mercury%22%2C%20%22Venus%22%2C%20%22Earth%22%2C%20%22Mars%22%5D%0A%0A%20%20%20%20planets%0A%20%20%20%20return%20(planets%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%20Access%20items%20by%20index%20(position%2C%20starting%20from%200)%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(planets)%3A%0A%20%20%20%20print(planets%5B0%5D)%20%20%23%20Mercury%0A%20%20%20%20print(planets%5B2%5D)%20%20%23%20Earth%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%20Reverse%20index%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(planets)%3A%0A%20%20%20%20print(planets%5B-1%5D)%20%20%23%20Mars%0A%20%20%20%20print(planets%5B-3%5D)%20%20%23%20Venus%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%20Add%20an%20item%20to%20the%20end%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(planets)%3A%0A%20%20%20%20planets.append(%22Jupiter%22)%0A%0A%20%20%20%20planets%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%3E%20**Note%3A**%0A%20%20%20%20%3E%20Python%20has%20several%20useful%20built-in%20functions.%20One%20is%20%60len()%60%2C%20which%20we'll%20use%20below.%20It%20returns%20the%20length%20(i.e.%2C%20the%20number%20of%20items)%20of%20an%20object%20like%20a%20list%20or%20a%20string.%0A%0A%20%20%20%20Get%20the%20number%20of%20items%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(planets)%3A%0A%20%20%20%20len(planets)%20%20%23%20Output%3A%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%20Lists%20are%20mutable%20(can%20be%20changed%20after%20creation)%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(planets)%3A%0A%20%20%20%20planets%5B0%5D%20%3D%20%22Fast%20Planet%22%20%20%23%20Change%20the%20first%20item%0A%20%20%20%20planets%5B3%5D%20%3D%20%22Red%20Planet%22%20%20%23%20Update%20Mars%0A%0A%20%20%20%20planets%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%20Common%20list%20operations%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(planets)%3A%0A%20%20%20%20planets.insert(1%2C%20%22New%20Planet%22)%20%20%23%20Insert%20at%20a%20specific%20index%0A%20%20%20%20print(planets)%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%20Remove%20item%20at%20index%202%20and%20get%20its%20value%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(planets)%3A%0A%20%20%20%20removed_planet%20%3D%20planets.pop(2)%0A%20%20%20%20print(f%22Removed%3A%20%7Bremoved_planet%7D%22)%0A%20%20%20%20print(planets)%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%20Dictionaries%0A%0A%20%20%20%20Use%20dictionaries%20when%20you%20need%20to%20associate%20_values_%20with%20unique%20_keys_%20(like%20looking%20up%20a%20word%20in%20a%20dictionary%20to%20find%20its%20definition).%20They%20are%20very%20efficient%20for%20retrieving%20values%20when%20you%20know%20the%20key.%0A%0A%20%20%20%20Once%20data%20is%20stored%2C%20you%20can%20easily%20retrieve%20or%20update%20a%20value%20using%20its%20key.%0A%0A%20%20%20%20Dictionaries%20are%20defined%20using%20curly%20braces%20%60%7B%7D%60.%20Each%20item%20is%20a%20key-value%20pair%2C%20separated%20by%20a%20colon%20%60%3A%60.%20The%20key%20is%20on%20the%20left%2C%20and%20the%20value%20is%20on%20the%20right.%0A%0A%20%20%20%20Similar%20to%20lists%2C%20dictionaries%20use%20square%20brackets%20%60%5B%5D%60%20to%20access%20values%2C%20but%20instead%20of%20a%20numerical%20index%2C%20you%20use%20the%20key.%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%20%23%20Create%20a%20dictionary%20using%20curly%20braces%20%7B%7D%0A%20%20%20%20%23%20Format%3A%20%7Bkey1%3A%20value1%2C%20key2%3A%20value2%7D%0A%20%20%20%20building_info%20%3D%20%7B%22type%22%3A%20%22Residential%22%2C%20%22floors%22%3A%205%2C%20%22year_built%22%3A%201998%7D%0A%20%20%20%20building_info%0A%20%20%20%20return%20(building_info%2C)%0A%0A%0A%40app.cell%0Adef%20_(building_info)%3A%0A%20%20%20%20%23%20Access%20values%20using%20keys%0A%20%20%20%20print(building_info%5B%22type%22%5D)%20%20%23%20Residential%0A%20%20%20%20print(building_info%5B%22floors%22%5D)%20%20%23%205%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(building_info)%3A%0A%20%20%20%20%23%20Add%20a%20new%20key-value%20pair%0A%20%20%20%20building_info%5B%22has_elevator%22%5D%20%3D%20True%0A%20%20%20%20print(building_info)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(building_info)%3A%0A%20%20%20%20%23%20Dictionaries%20are%20mutable%0A%20%20%20%20building_info%5B%22year_built%22%5D%20%3D%202000%20%20%23%20Update%20a%20value%0A%20%20%20%20print(building_info)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(building_info)%3A%0A%20%20%20%20%23%20Common%20dictionary%20operations%0A%20%20%20%20print(building_info.keys())%20%20%23%20Get%20all%20keys%0A%20%20%20%20print(building_info.values())%20%20%23%20Get%20all%20values%0A%20%20%20%20print(building_info.get(%22floors%22))%20%20%23%20Get%20value%0A%20%20%20%20print(building_info.get(%22address%22))%20%20%23%20Returns%20None%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%20Tuples%0A%0A%20%20%20%20Use%20tuples%20for%20ordered%20collections%20of%20items%20that%20shouldn't%20change%20after%20creation%20(e.g.%2C%20coordinates).%20Tuples%20are%20_immutable_%2C%20meaning%20they%20cannot%20be%20altered%20once%20created.%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%20%23%20A%20tuple%20of%20coordinates%0A%20%20%20%20point%20%3D%20(10.5%2C%2025.3)%0A%20%20%20%20print(point)%0A%20%20%20%20print(point%5B0%5D)%20%20%23%20Access%20items%20like%20lists%0A%20%20%20%20return%20(point%2C)%0A%0A%0A%40app.cell%0Adef%20_(point)%3A%0A%20%20%20%20%23%20This%20would%20cause%20a%20TypeError!%20Tuples%20are%20immutable.%0A%20%20%20%20point%5B0%5D%20%3D%2011.0%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%20Tuples%20are%20often%20used%20to%20return%20multiple%20values%20from%20functions%20or%20for%20unpacking%20(we%20will%20explain%20functions%20later).%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.function%0Adef%20get_coordinates()%3A%0A%20%20%20%20return%20(10.5%2C%2025.3)%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%20This%20is%20a%20common%20pattern%20in%20Python%2C%20especially%20when%20dealing%20with%20functions%20that%20return%20multiple%20values.%20You%20can%20unpack%20the%20tuple%20into%20separate%20variables.%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%20coords%20%3D%20get_coordinates()%0A%20%20%20%20_lat%2C%20_lon%20%3D%20coords%20%20%23%20Tuple%20unpacking%0A%20%20%20%20print(f%22Latitude%3A%20%7B_lat%7D%2C%20Longitude%3A%20%7B_lon%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%20The%20above%20can%20also%20be%20done%20directly%3A%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%20_lat%2C%20_lon%20%3D%20get_coordinates()%0A%20%20%20%20print(f%22Latitude%3A%20%7B_lat%7D%2C%20Longitude%3A%20%7B_lon%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%20The%20below%20would%20raise%20an%20error%20because%20the%20tuple%20only%20has%20two%20items%2C%20but%20we%20are%20trying%20to%20unpack%20it%20into%20three%20variables%3A%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%20_lat%2C%20_lon%2C%20z%20%3D%20get_coordinates()%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%20Sets%0A%0A%20%20%20%20Use%20sets%20when%20you%20need%20a%20collection%20of%20unique%20items%2C%20and%20the%20order%20of%20those%20items%20isn't%20important.%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%20%23%20Duplicate%20%22London%22%20is%20ignored%0A%20%20%20%20unique_cities%20%3D%20%7B%22London%22%2C%20%22Paris%22%2C%20%22Berlin%22%7D%0A%20%20%20%20%23%20Output%20might%20be%20in%20any%20order%2C%20e.g.%2C%20%7B'Berlin'%2C%20'London'%2C%20'Paris'%7D%0A%20%20%20%20print(unique_cities)%0A%20%20%20%20return%20(unique_cities%2C)%0A%0A%0A%40app.cell%0Adef%20_(unique_cities)%3A%0A%20%20%20%20%23%20Check%20for%20membership%0A%20%20%20%20print(%22Paris%22%20in%20unique_cities)%20%20%23%20True%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(unique_cities)%3A%0A%20%20%20%20%23%20Add%20an%20item%0A%20%20%20%20unique_cities.add(%22Rome%22)%0A%20%20%20%20print(unique_cities)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20%23%20Set%20operations%0A%20%20%20%20set1%20%3D%20%7B1%2C%202%2C%203%7D%0A%20%20%20%20set2%20%3D%20%7B3%2C%204%2C%205%7D%0A%20%20%20%20print(set1.union(set2))%20%20%23%20All%20items%20from%20both%3A%20%7B1%2C%202%2C%203%2C%204%2C%205%7D%0A%20%20%20%20print(set1.intersection(set2))%20%20%23%20Items%20in%20both%3A%20%7B3%7D%0A%20%20%20%20print(set1.difference(set2))%20%20%23%20Items%20in%20set1%20but%20not%20set2%3A%20%7B1%2C%202%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%23%20Collection%20Exercises%0A%0A%20%20%20%20-%20Create%20a%20dictionary%20representing%20a%20building%20with%20keys%20for%20%60name%60%2C%20%60height%60%2C%20and%20%60year_built%60.%20Print%20the%20building's%20height.%0A%20%20%20%20-%20Create%20a%20list%20of%20five%20city%20names.%20Use%20a%20loop%20to%20print%20each%20city%20name%20in%20uppercase%20(hint%3A%20%60%22text%22.upper()%60).%0A%0A%20%20%20%20%23%23%20Control%20Flow%0A%0A%20%20%20%20Control%20flow%20structures%20are%20fundamental%20to%20programming.%20They%20allow%20your%20code%20to%20make%20decisions%20(using%20%60if%60%2F%60elif%60%2F%60else%60)%20and%20repeat%20actions%20(using%20%60for%60%2F%60while%60%20loops).%0A%0A%20%20%20%20%23%23%23%20Conditionals%0A%0A%20%20%20%20Conditionals%20allow%20your%20program%20to%20execute%20different%20blocks%20of%20code%20based%20on%20whether%20certain%20conditions%20are%20%60True%60%20or%20%60False%60.%20They%20use%20comparison%20operators%20to%20evaluate%20conditions.%20This%20conditional%20logic%20enables%20your%20program%20to%20adapt%20its%20behaviour%20to%20various%20situations.%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%20%23%20Comparison%20operators%20return%20boolean%20values%0A%20%20%20%20print(5%20%3D%3D%205)%20%20%23%20Equal%20to%3A%20True%0A%20%20%20%20print(5%20!%3D%203)%20%20%23%20Not%20equal%20to%3A%20True%0A%20%20%20%20print(5%20%3E%203)%20%20%23%20Greater%20than%3A%20True%0A%20%20%20%20print(5%20%3C%203)%20%20%23%20Less%20than%3A%20False%0A%20%20%20%20print(5%20%3E%3D%205)%20%20%23%20Greater%20than%20or%20equal%20to%3A%20True%0A%20%20%20%20print(5%20%3C%3D%203)%20%20%23%20Less%20than%20or%20equal%20to%3A%20False%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%3E%20**Note%3A**%0A%20%20%20%20%3E%20%23%23%23%20Indentation%0A%20%20%20%20%3E%0A%20%20%20%20%3E%20Indentation%20is%20non-negotiable%20in%20Python%3A%20it%20defines%20code%20blocks.%20Always%20use%20consistent%20spacing%20(the%20common%20convention%20is%204%20spaces%20per%20indentation%20level)%20and%20avoid%20mixing%20spaces%20with%20tabs.%20Code%20blocks%20are%20introduced%20by%20a%20colon%20(%60%3A%60)%20and%20can%20be%20nested.%0A%20%20%20%20%3E%0A%20%20%20%20%3E%20%60%60%60python%0A%20%20%20%20%3E%20%23%20FYI%20-%20we%20will%20explain%20loops%20next%0A%20%20%20%20%3E%20for%20i%20in%20range(3)%3A%0A%20%20%20%20%3E%20%20%20%20%20%23%20Example%20of%20indentation%0A%20%20%20%20%3E%20%20%20%20%20if%20i%20%3D%3D%202%3A%0A%20%20%20%20%3E%20%20%20%20%20%20%20%20%20%23%20Example%20of%20nested%20indentation%0A%20%20%20%20%3E%20%20%20%20%20%20%20%20%20print(f%22%7Bi%7D%20is%20two%22)%0A%20%20%20%20%3E%20%20%20%20%20else%3A%0A%20%20%20%20%3E%20%20%20%20%20%20%20%20%20print(f%22%7Bi%7D%20is%20not%20two%22)%0A%20%20%20%20%3E%20%60%60%60%0A%0A%20%20%20%20Use%20%60if%60%2C%20%60elif%60%20(short%20for%20'else%20if')%2C%20and%20%60else%60%20to%20direct%20the%20flow%20of%20execution.%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%20population_density%20%3D%205000%20%20%23%20people%20per%20sq%20km%0A%0A%20%20%20%20if%20population_density%20%3E%2010000%3A%0A%20%20%20%20%20%20%20%20print(%22Very%20high%20density%22)%0A%20%20%20%20elif%20population_density%20%3E%203000%3A%0A%20%20%20%20%20%20%20%20print(%22High%20density%22)%0A%20%20%20%20elif%20population_density%20%3E%201000%3A%0A%20%20%20%20%20%20%20%20print(%22Medium%20density%22)%0A%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20print(%22Low%20density%22)%0A%20%20%20%20return%20(population_density%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%20Conditions%20can%20be%20combined%20using%20%60and%60%20and%20%60or%60.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(population_density)%3A%0A%20%20%20%20%23%20Combining%20conditions%20with%20'and'%2C%20'or'%0A%20%20%20%20floors%20%3D%2012%0A%0A%20%20%20%20if%20population_density%20%3E%203000%20and%20floors%20%3E%2010%3A%0A%20%20%20%20%20%20%20%20print(%22High%20density%20and%20tall%20buildings%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%20For%20identity%20checks%20(e.g.%2C%20if%20a%20value%20%60is%20None%60)%2C%20use%20%60is%60%20and%20%60is%20not%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%20%23%20Checking%20for%20None%20(often%20used%20for%20missing%20data)%0A%20%20%20%20maybe_data%20%3D%20None%20%20%23%20Represents%20absence%20of%20a%20value%0A%0A%20%20%20%20if%20maybe_data%20is%20None%3A%0A%20%20%20%20%20%20%20%20print(%22Data%20is%20missing.%22)%0A%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20print(f%22Data%20found%3A%20%7Bmaybe_data%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%20For%20checking%20if%20a%20value%20is%20in%20a%20collection%20(like%20a%20list%20or%20set)%2C%20use%20%60in%60%20and%20%60not%20in%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%20%23%20Check%20if%20a%20value%20is%20in%20a%20list%0A%20%20%20%20cities%20%3D%20%5B%22London%22%2C%20%22Paris%22%2C%20%22Berlin%22%5D%0A%20%20%20%20if%20%22Paris%22%20in%20cities%3A%0A%20%20%20%20%20%20%20%20print(%22Paris%20is%20in%20the%20list%20of%20cities.%22)%0A%20%20%20%20if%20%22Rome%22%20not%20in%20cities%3A%0A%20%20%20%20%20%20%20%20print(%22Rome%20is%20not%20in%20the%20list%20of%20cities.%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%20Loops%0A%0A%20%20%20%20Loops%20are%20fantastic%20for%20avoiding%20repetitive%20code.%20They%20are%20essential%20for%20processing%20items%20in%20collections%20and%20can%20be%20combined%20with%20conditionals%20to%20apply%20logic%20selectively%20to%20each%20item.%0A%0A%20%20%20%20%23%23%23%23%20%60for%60%20Loops%0A%0A%20%20%20%20Use%20%60for%60%20loops%20to%20iterate%20over%20each%20item%20in%20a%20sequence%20(such%20as%20a%20list%2C%20tuple%2C%20or%20string).%20In%20each%20pass%20(iteration)%2C%20the%20loop%20variable%20(e.g.%2C%20%60planet%60%20in%20the%20example%20below)%20takes%20the%20value%20of%20the%20current%20item%20from%20the%20sequence.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(planets)%3A%0A%20%20%20%20%23%20Loop%20through%20a%20list%0A%20%20%20%20for%20planet%20in%20planets%3A%0A%20%20%20%20%20%20%20%20print(f%22Checking%20planet%3A%20%7Bplanet%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%23%23%20%60while%60%20Loops%0A%0A%20%20%20%20Use%20%60while%60%20loops%20when%20you%20don't%20know%20exactly%20how%20many%20times%20to%20loop%20in%20advance%2C%20but%20you%20know%20the%20condition%20under%20which%20the%20loop%20should%20continue%20running.%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%20%23%20Countdown%0A%20%20%20%20countdown%20%3D%203%0A%20%20%20%20while%20countdown%20%3E%200%3A%0A%20%20%20%20%20%20%20%20print(countdown)%0A%20%20%20%20%20%20%20%20%23%20Decrease%20countdown%20(essential%20to%20avoid%20infinite%20loop!!!)%0A%20%20%20%20%20%20%20%20countdown%20%3D%20countdown%20-%201%0A%20%20%20%20print(%22Blast%20off!%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**Caution%3A**%20Ensure%20the%20%60while%60%20loop's%20condition%20eventually%20becomes%20%60False%60%2C%20otherwise%20it%20will%20run%20forever%20(an%20infinite%20loop)!%0A%0A%20%20%20%20%23%23%23%20Exercise%0A%0A%20%20%20%20Create%20a%20list%20named%20%60numbers%60%20containing%20the%20integers%20from%201%20to%2010.%20Then%2C%20write%20a%20loop%20that%20iterates%20through%20this%20list.%20For%20each%20number%2C%20if%20it%20is%20even%2C%20print%20the%20number.%0A%0A%20%20%20%20**Hint%3A**%20The%20modulo%20operator%20(%60%25%60)%20gives%20the%20remainder%20of%20a%20division.%20A%20number%20is%20even%20if%20%60number%20%25%202%20%3D%3D%200%60.%0A%0A%20%20%20%20%23%23%20Functions%0A%0A%20%20%20%20Functions%20help%20you%20organise%20your%20code%20into%20logical%2C%20reusable%20blocks.%20This%20improves%20readability%2C%20makes%20debugging%20easier%2C%20and%20simplifies%20maintenance.%20If%20you%20find%20yourself%20copying%20and%20pasting%20code%2C%20that's%20often%20a%20good%20sign%20you%20could%20write%20a%20function%20instead.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.function%0A%23%20Define%20a%20function%20with%20parameters%20(inputs)%0Adef%20calculate_density(population%2C%20area%2C%20unit%3D%22sq%20km%22)%3A%0A%20%20%20%20%22%22%22Calculates%20population%20density.%0A%0A%20%20%20%20It's%20good%20practice%20to%20include%20a%20*docstring*%20(documentation%20string)%20right%20after%0A%20%20%20%20the%20def%20line%20to%20explain%20what%20the%20function%20does%2C%20its%20parameters%2C%20and%20what%20it%20returns.%0A%0A%20%20%20%20Args%3A%0A%20%20%20%20%20%20%20%20population%20(int)%3A%20The%20total%20population.%0A%20%20%20%20%20%20%20%20area%20(float)%3A%20The%20total%20area.%0A%20%20%20%20%20%20%20%20unit%20(str%2C%20optional)%3A%20The%20unit%20for%20the%20area.%20Defaults%20to%20%22sq%20km%22.%0A%0A%20%20%20%20Returns%3A%0A%20%20%20%20%20%20%20%20float%3A%20The%20calculated%20density%2C%20or%200%20if%20area%20is%20non-positive.%0A%20%20%20%20%22%22%22%0A%20%20%20%20if%20area%20%3C%3D%200%3A%0A%20%20%20%20%20%20%20%20print(%22Area%20must%20be%20positive%20to%20calculate%20density.%22)%0A%20%20%20%20%20%20%20%20return%200%20%20%23%20Return%200%20or%20raise%20an%20error%20for%20invalid%20input%0A%20%20%20%20density%20%3D%20population%20%2F%20area%0A%20%20%20%20return%20density%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-%20**Parameters%3A**%20These%20are%20the%20names%20listed%20in%20the%20function%20definition's%20parentheses%20(e.g.%2C%20%60population%60%2C%20%60area%60).%0A%20%20%20%20-%20**Arguments%3A**%20These%20are%20the%20actual%20values%20you%20pass%20to%20the%20function%20when%20you%20call%20it.%0A%20%20%20%20-%20**Default%20Arguments%3A**%20You%20can%20give%20parameters%20default%20values%20(e.g.%2C%20%60unit%3D%22sq%20km%22%60).%20If%20you%20don't%20provide%20an%20argument%20for%20that%20parameter%20when%20calling%20the%20function%2C%20the%20default%20value%20is%20used.%0A%20%20%20%20-%20**Scope%3A**%20Variables%20defined%20inside%20a%20function%20are%20typically%20_local_%20to%20that%20function%2C%20meaning%20they%20only%20exist%20and%20can%20be%20accessed%20within%20that%20function.%0A%20%20%20%20-%20**Docstrings%3A**%20As%20mentioned%2C%20the%20optional%20triple-quoted%20string%20right%20after%20the%20%60def%60%20line.%20They%20are%20used%20to%20document%20what%20the%20function%20does%2C%20its%20arguments%20(often%20listed%20under%20an%20%60Args%3A%60%20section)%2C%20and%20what%20it%20returns%20(under%20a%20%60Returns%3A%60%20section).%0A%20%20%20%20-%20**Return%20Statement%3A**%20The%20%60return%60%20statement%20is%20used%20to%20send%20a%20value%20back%20from%20the%20function%20to%20the%20place%20where%20it%20was%20called.%20If%20a%20function%20doesn't%20have%20a%20%60return%60%20statement%2C%20or%20if%20the%20%60return%60%20statement%20is%20used%20without%20a%20value%2C%20it%20implicitly%20returns%20%60None%60.%0A%0A%20%20%20%20Call%20the%20function%20with%20arguments%20(values%20for%20the%20parameters)%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%20density1%20%3D%20calculate_density(1000000%2C%2050)%0A%20%20%20%20print(f%22Density%201%3A%20%7Bdensity1%3A.2f%7D%20people%20per%20sq%20km%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%20Calling%20the%20function%20with%20explicit%20named%20arguments%20allows%20you%20to%20specify%20which%20parameter%20each%20value%20corresponds%20to%2C%20making%20your%20code%20clearer%20and%20more%20readable.%20This%20is%20especially%20useful%20when%20a%20function%20has%20many%20parameters%20or%20some%20have%20default%20values.%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%20%23%20Can%20name%20arguments%0A%20%20%20%20density2%20%3D%20calculate_density(population%3D500000%2C%20area%3D100%2C%20unit%3D%22square%20kilometres%22)%0A%20%20%20%20print(f%22Density%202%3A%20%7Bdensity2%3A.2f%7D%20people%20per%20square%20kilometres%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%20While%20functions%20don't%20always%20have%20to%20return%20a%20value%20(e.g.%2C%20a%20function%20that%20just%20prints%20something)%2C%20they%20often%20do.%0A%0A%20%20%20%20%23%23%23%20Function%20Exercise%0A%0A%20%20%20%20Write%20a%20function%20called%20%60classify_building%60%20that%20takes%20a%20%60height%60%20parameter%20and%20returns%20%60%22low-rise%22%60%20if%20height%20%3C%2010%2C%20%60%22mid-rise%22%60%20if%2010%E2%80%9325%2C%20and%20%60%22high-rise%22%60%20if%20%3E%2025.%20Test%20it%20with%20three%20different%20heights.%0A%0A%20%20%20%20%23%23%20Importing%20Modules%0A%0A%20%20%20%20Python%20has%20a%20vast%20collection%20of%20_modules_%20that%20provide%20ready-to-use%20tools%2C%20so%20you%20often%20don't%20need%20to%20reinvent%20the%20wheel.%20If%20you%20encounter%20an%20unfamiliar%20function%2C%20it's%20a%20good%20idea%20to%20check%20the%20%60import%60%20statements%2C%20usually%20found%20at%20the%20top%20of%20the%20file%2C%20as%20the%20function%20might%20come%20from%20an%20imported%20module.%0A%0A%20%20%20%20%60import%20module_name%60%20makes%20the%20functions%20and%20variables%20within%20that%20module%20available%2C%20accessed%20via%20%60module_name.function_name%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%20import%20math%20%20%23%20Import%20the%20built-in%20math%20module%0A%0A%20%20%20%20radius%20%3D%205%0A%20%20%20%20area%20%3D%20math.pi%20*%20(radius**2)%20%20%23%20Use%20math.pi%0A%20%20%20%20print(f%22Circle%20Area%3A%20%7Barea%3A.2f%7D%22)%0A%20%20%20%20return%20math%2C%20radius%0A%0A%0A%40app.cell%0Adef%20_(math%2C%20radius)%3A%0A%20%20%20%20circumference%20%3D%202%20*%20math.pi%20*%20radius%0A%20%20%20%20print(f%22Circle%20Circumference%3A%20%7Bcircumference%3A.2f%7D%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20%23%20You%20can%20also%20import%20specific%20methods%20from%20a%20module%0A%20%20%20%20from%20math%20import%20sqrt%20%20%23%20Import%20only%20the%20square%20root%20function%0A%0A%20%20%20%20print(f%22Square%20root%20of%2016%20is%20%7Bsqrt(16)%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%20In%20later%20sections%2C%20we'll%20be%20making%20extensive%20use%20of%20powerful%20libraries%20such%20as%20%60geopandas%60%20and%20%60numpy%60%2C%20which%20are%20imported%20as%20modules.%0A%0A%20%20%20%20%23%23%20Common%20Errors%0A%0A%20%20%20%20Errors%20are%20a%20normal%20part%20of%20programming.%20Learning%20to%20read%20and%20understand%20error%20messages%20is%20a%20key%20skill%20for%20fixing%20them.%20If%20you%20get%20stuck%2C%20searching%20for%20the%20error%20message%20online%20is%20often%20helpful%3B%20chances%20are%2C%20someone%20else%20has%20encountered%20the%20same%20problem.%20You%20can%20also%20ask%20an%20LLM%20to%20help%20explain%20what%20an%20error%20message%20means.%0A%0A%20%20%20%20-%20**%60NameError%3A%20name%20'...'%20is%20not%20defined%60**%3A%20You%20tried%20to%20use%20a%20variable%20before%20assigning%20a%20value%20to%20it%2C%20or%20you%20misspelled%20the%20variable%20name.%0A%20%20%20%20-%20**%60TypeError%3A%20unsupported%20operand%20type(s)%20for%20...%60**%3A%20You%20tried%20to%20perform%20an%20operation%20on%20incompatible%20data%20types%20(e.g.%2C%20adding%20a%20string%20to%20an%20integer%3A%20%60%22Hello%22%20%2B%205%60).%0A%20%20%20%20-%20**%60SyntaxError%3A%20invalid%20syntax%60**%3A%20You%20made%20a%20mistake%20in%20the%20Python%20grammar%20(e.g.%2C%20missing%20colon%20%60%3A%60%2C%20mismatched%20parentheses%20%60()%60).%0A%20%20%20%20-%20**%60IndexError%3A%20list%20index%20out%20of%20range%60**%3A%20You%20tried%20to%20access%20an%20item%20in%20a%20list%20using%20an%20index%20that%20doesn't%20exist%20(e.g.%2C%20accessing%20%60my_list%5B5%5D%60%20when%20the%20list%20only%20has%203%20items).%0A%20%20%20%20-%20**%60ImportError%3A%20No%20module%20named%20'...'%60%20or%20%60ModuleNotFoundError%3A%20No%20module%20named%20'...'%60**%3A%20You%20tried%20to%20import%20a%20module%20that%20Python%20can't%20find.%20It%20might%20be%20misspelled%20or%20not%20installed.%0A%0A%20%20%20%20**Debugging%20Tip%3A**%20When%20you%20encounter%20an%20error%2C%20the%20last%20line%20of%20the%20message%20usually%20tells%20you%20the%20specific%20type%20of%20error.%20The%20lines%20mentioned%20in%20the%20traceback%20help%20you%20find%20where%20the%20problem%20occurred%20in%20your%20code.%20Sprinkling%20%60print()%60%20statements%20in%20your%20code%20to%20check%20the%20values%20of%20variables%20at%20different%20stages%20can%20also%20be%20a%20very%20effective%20way%20to%20debug.%20And%20remember%2C%20it's%20common%20to%20fix%20one%20error%20only%20to%20find%20another%3B%20just%20tackle%20them%20one%20by%20one.%0A%0A%20%20%20%20%23%23%20Summary%0A%0A%20%20%20%20-%20Python%20variables%20store%20data%20of%20different%20types%3A%20strings%2C%20integers%2C%20floats%2C%20and%20booleans.%0A%20%20%20%20-%20Collections%20(lists%2C%20dictionaries%2C%20tuples%2C%20sets)%20let%20you%20group%20related%20data%2C%20each%20with%20different%20characteristics%20for%20ordering%2C%20uniqueness%2C%20and%20mutability.%0A%20%20%20%20-%20Control%20flow%20with%20%60if%60%2F%60elif%60%2F%60else%60%20and%20%60for%60%2F%60while%60%20loops%20lets%20your%20code%20make%20decisions%20and%20repeat%20actions.%0A%20%20%20%20-%20Functions%20organise%20reusable%20logic%2C%20accept%20parameters%2C%20and%20return%20results.%0A%20%20%20%20-%20Modules%20extend%20Python's%20capabilities%3B%20import%20them%20to%20access%20ready-made%20tools.%0A%20%20%20%20-%20Errors%20are%20normal%3B%20reading%20the%20traceback%20and%20error%20type%20is%20the%20key%20to%20debugging.%0A%0A%20%20%20%20Next%3A%20%5BSpatial%20Data%5D(https%3A%2F%2Fcityseer.benchmarkurbanism.com%2Fstart%2F3-spatial)%20introduces%20geometric%20objects%20with%20Shapely.%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
844462556b9e83d500b5744c3e8aeb6b