In Class Activity - Python - For loops¶
Problem 0: For-loop over a dictionary¶
Here is a dictionary colleges
that lists the city and zip (as values) for several schools in NYC (as keys).
colleges = {}
colleges['NYU'] = 'New York, NY 10012'
colleges['Columbia'] = 'New York, NY 10027'
colleges['Fordham'] = 'Bronx, NY 10458'
colleges['Brooklyn college'] = 'Brooklyn, NY 11210'
Write a for-loop to iterate over the keys and return the values, printing in this format:
# Your answer goes here
Problem 1: Multiplication table¶
Write a function mult_table(n)
that produces the multiplication table below. Note that for each cell \(c_{ij}\), its value is equal to the product of the row number \(i\) and column number \(j\), assuming they are numbered \(1,\dots,n\).
Note, it’s not necessary to get the spacing exactly as in the example, but kudos if you do!
Here is what the output should look like when you run mult_table(10)
# Your answer goes here