Sep 27: Group Activity - For Loops
Room: King Hall 260
Group Activity¶
- For Loops and Ranges
- If you are absent today, complete this activity at home
- Please don't forget to do the survey for 3 points
Example Code¶
Model 1
print("hello")
for x in [2, 7, 1]:
print("the number is", x)
print("goodbye")
Question 8
for c in "Hi!":
print(c)
Model 2
range(5)
list(range(5))
x = range(3)
print(x)
print(list(x))
list(range(5, 10))
list(range(-3, 4))
list(range(4, 10, 2))
for i in range(5):
print(i)
Model 3
names = ["emma", "liam", "aisha", "mateo", "sofia", "ravi"]
for i in range(len(names)):
name = names[i]
# replace element at index i
names[i] = name.capitalize()
Question 24
prices = [19.99, 6.34, 1.00, 12.79, 2.50]