


SDA intros





Questions





Get to know you activity





Refresh





arithmetic operators





variable name on left side vs right side





to make variable names easier to read, convention is to use underscores or capitalization





cur_temp or curTemp





the former is called snake case and the latter is called camel case





what might make for a good variable name?





not too long





describes what the variable represents





Problem: what icon to display in weather app?





Simplified problem: difference between current and “hot” temperature (i.e., should the app show the current temperature in red)





calculate difference





difference = hot_temp  cur_temp_F





make a diagram of memory after each step (line of code)





diagram the following steps





x = 10 y = x x = x + 5





y and x label separate locations in memory, the second step copies the value stored as x to a new location and labels it y





so the third line overwrites the value for x, but not for y





[NOW ON SCREEN] output result (three mistakes: missing “, missing ), typo in variable name)





Forgetting a close “ around text causes a SyntaxError





anatomy of the error message





File where the error occurred, line where the error occurred, and the error type and message





it may feel like it’s Python yelling at you for your mistakes





really Python catching on fire and saying “I don’t understand, aaaaaaaahhhhhhhhhh.”





how would you demonstrate to me this is correct (or incorrect)





print everything, check for known results





compare to oneline version





print(“difference between hot and current temp in Celsius:”, (80  32) / 9 * 5  get_cur_temp())





comments





any line that starts with a # is a comment





ignored by Python, useful for explaining and documenting your code





Python Standard Library





https://docs.python.org/3/library/index.html





Made up of modules which are made available by importing them





example





import math print(math.sqrt(100)) # prints 10 print(math.sqrt(100)) # causes ValueError since sqrt doesn’t know how to handle negative numbers





Note how we access sqrt by writing <module name>.sqrt, this is how modules work in general





Variation on import





from math import sqrt





lets us just write sqrt instead of math.sqrt


