sudo apt install i3
i3 package group comes with i3-wm, i3status, and i3lock packages
The squirrels in Palo Alto spend most of the day playing. In particular, they play if the temperature is between 60 and 90 (inclusive). Unless it is summer, then the upper limit is 100 instead of 90. Given an int temperature and a Boolean is_summer, return True if the squirrels play and False otherwise.
def squirrel_play(temp, is_summer):
this is block 1
this is block 1
this is block 2
this is block 2
this is block 2
this is block 3
this is block 3
this is block 2
this is block 1
this is block 1
for variable in list:
The variable iterates through the list and is assigned the value of the current iteration
for x in range(5):
y = x + 1
print(x+y)
for s in myList:
print(s)
>>> savings = 0
>>> for week in range(1, 53):
... savings = savings + 35
... print("Week %s = $%s" % (week, savings))
>>> myList = ['a', 'b', 'c']
>>> for u in myList:
... print(u)
... for v in myList:
... print(v)
If you have $100 saved in your bank account, and you obtain 3% interest every year, how much money will you have for each year, up to 10 years?
while condition:
# block of code
x = 1
while x < 200:
x = 2*x
print(x)
What will this print?
Answer the previous question using a while loop
If you don't remember the task:
If you have $100 saved in your bank account, and you obtain 3% interest every year, how much money will you have for each year, up to 10 years?
def function(parameter):
# block of code
You define (make) the function like this:
def printName(name):
print("Hello, %s!" % name)
And call (use) it like this:
printName("John")
Which will print:
Hello, John!
Another example, except with return instead of print():
def savings(chores, job, spending):
return chores + job - spending
# or return(chores+job-spending)
And call it like this:
print(savings(10, 10, 5))
# OR
money = savings(10, 10, 5)
When a function returns a value, that value becomes the value of the function
def cow(name):
return("My cow is named: " + name)
cow("Bob") #nothing will be outputted
myCow = cow("Bob")
cows = [cow("Bob"), cow("Spot"), cow("Hoover")]
# This is a global variable
a = 0
if a == 0:
# This is still a global variable
b = 1
def my_function(c):
# this is a local variable
d = 3
print(c)
print(d)
# Now we call the function, passing the value 7
# as the first and only parameter
my_function(7)
# a and b still exist
print(a)
print(b)
# c and d don't exist anymore -- these statements
# will give us name errors!
print(c)
print(d)