




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





Today ...
Homework
Reminder
Comments are special notes you can add to your programs
It’s always a good idea to comment your code
Regular comments start with a # in Python
percentage = (minute * 100) / 60
percentage = (minute * 100) / 60 # percentage of an hour
Comments are useful when they highlight non-obvious features v = 5 # assign 5 to v
v = 5 # velocity in meter/second
You should always try to choose descriptive variable and function names
Put at least one blank line between header and function definitions
Incorrect:
def f(x): print(x)
Correct:
def f(x): print(x)
Put a blank line between function definitions
Incorrect: def f(x): print(x) def g(x): print(x)
Correct:
def f(x): print(x)
def g(x): print(x)
Don’t put white space before or after function ()’s
Incorrect:
def f (x) : print(x)
Correct:
def f(x): print(x)
Put white space between arguments/parameters
Incorrect:
def f(x,y): print(x,y)
Correct:
def f(x, y): print(x, y)
Expressions are statements that always evaluate to (return) a value
Expressions can combine values, variables, and operators
Examples of expressions
What should the value of the last expression be?
Beware the Python interpreter! (common mistake)
>>> 1 + 1 2
An aside – What happens if we enter the following: >>> 12 = 3* SyntaxError: can’t assign to literal
Precendence rules define the order of operator evaluation
This spells PEMDAS