Give students time to experiment on their own and emphasize the power of experimenting!
Allow students to practice and experiment
=
for assignment and ==
for comparison+
).toupper()
as an intro to the concept of methodsAllow students to practice specifying, converting, and checking types (2:00-2:10)
weight_kg = 65
) https://swcarpentry.github.io/python-novice-inflammation/instructor/01-intro.html#variablesweight_lb = 2.2 * weight_kg
)Work through SWCarpentry materials: https://swcarpentry.github.io/python-novice-inflammation/instructor/04-lists.html
my_string.split()
len()
.append()
, .pop()
, and .reverse()
- use this to reinforce the concept of methodsfor
loops (2:55 - 3:45; live coding)Motivate the use of loops for performing a repeated action - copy and paste print statements (2:55 - 3:00)
for
loop syntax (3:00-3:10)
range()
f = open("mouseBed.bed", "r")
lines = f.readlines()
for i in range(2000):
print(lines[i])
f.close()
.strip()
to remove the whitespacef = open("mouseBed.bed", "r")
lines = f.readlines()
for i in range(2000):
line = lines[i].strip()
print(line)
f.close()
f = open("mouseBed.bed", "r")
lines = f.readlines()
for i in range(2000):
line_string = lines[i].strip()
line_list = line_string.split()
print(line_list[1])
f.close()
f = open("mouseBed.bed", "r")
lines = f.readlines()
for i in range(2000):
line_string = lines[i].strip()
line_list = line_string.split()
print(type(line_list[1]))
f.close()
f = open("mouseBed.bed", "r")
lines = f.readlines()
for i in range(2000):
line_string = lines[i].strip()
line_list = line_string.split()
start_coord = int(line_list[1])
print(start_coord)
f.close()
f = open("mouseBed.bed", "r")
lines = f.readlines()
start_coord_list = []
for i in range(2000):
line_string = lines[i].strip()
line_list = line_string.split()
start_coord = int(line_list[1])
start_coord_list.append(start_coord)
f.close()
print(start_coord_list)
f = open("mouseBed.bed", "r")
lines = f.readlines()
start_coord_list = []
for i in range(2000):
line_string = lines[i].strip()
line_list = line_string.split()
start_coord = int(line_list[1])
start_coord_list.append(start_coord)
f.close()
start_coord_list.reverse()
print(start_coord_list)
f = open("mouseBed.bed", "r")
lines = f.readlines()
start_coord_list = []
sum = 0
for i in range(2000):
line_string = lines[i].strip()
line_list = line_string.split()
start_coord = int(line_list[1])
start_coord_list.append(start_coord)
sum = sum + start_coord
f.close()
print(sum / len(start_coord_list))
import numpy
f = open("mouseBed.bed", "r")
lines = f.readlines()
start_coord_list = []
for i in range(2000):
line_string = lines[i].strip()
line_list = line_string.split()
start_coord = int(line_list[1])
start_coord_list.append(start_coord)
f.close()
start_coord_mean = numpy.mean(start_coord_list)
print(start_coord_mean)
Give students time to practice writing and using for loops (SWCarpentry exercises; 3:30-3:45)
Exercise prepared by Andrew and Matthew