Friday 11/10
POGIL
Act11-Nested.pdf
Model 1
# current state of the game
grid = [
[' ', ' ', ' ', ' ', ' ', ' ', ' '],
[' ', ' ', ' ', ' ', ' ', ' ', ' '],
['Y', ' ', ' ', ' ', 'Y', 'Y', ' '],
['R', ' ', ' ', 'Y', 'R', 'R', ' '],
['R', 'R', 'Y', 'R', 'Y', 'R', ' '],
['R', 'Y', 'R', 'Y', 'Y', 'Y', 'R'],
]
print(grid)
print(grid[5])
print(grid[5][0])
type(grid)
type(grid[5])
type(grid[5][0])
len(grid)
len(grid[5])
len(grid[5][0])
import pprint
help(pprint)
pprint.pprint(grid)
for item in grid:
print(item)
for i in range(len(grid)):
print(grid[i])
Model 2
Example A
groceries = ["Apples", "Milk", "Flour", "Chips"]
for item in groceries:
print("Don't forget the", item)
Example B
count = 0
for row in grid: # outer loop
print("row =", row)
for cell in row: # inner loop
print("cell =", cell)
if cell == ' ':
count += 1
print(count, "spaces remaining")
Q13
for i in range(6):
for j in range(7):
print(i, '+', j, '=', i + j)
Model 3
movies = {
"Casablanca": {
"year": 1942,
"genres": ["Drama", "Romance", "War"],
},
"Star Wars": {
"year": 1977,
"genres": ["Action", "Adventure", "Fantasy"],
},
"Groundhog Day": {
"year": 1993,
"genres": ["Comedy", "Fantasy", "Romance"],
},
}
movies
movies["Casablanca"]
movies["Casablanca"]["year"]
movies["Casablanca"]["genres"]
type(movies)
type(movies["Casablanca"])
type(movies["Casablanca"]["year"])
type(movies["Casablanca"]["genres"])
len(movies)
len(movies["Casablanca"])
len(movies["Casablanca"]["year"])
len(movies["Casablanca"]["genres"])
for key in movies:
print(key)
for key, val in movies.items():
print(key, val)