Lab 7 Nested For Loops

Worksheet Links

Worksheet: print version| flat version

A. Warm up exercises

Write what each snippet of code produces:

  1. for x in [1, 4, 10]:
       for y in [7, 8]:
           print (x + y)
  2. for let in 'pie':
       for num in [2, 5, 0]:
            print (let * num)
  3. for num1 in range(1,4):
       for num2 in range(1,num1+1):
           print ('O' * num1 + 'H'* num2)

Table of Contents