Python Homework #3

Instructions:

Work through these to figure out what they do. Once you're done, submit to the homework server in the "comments-to-teacher" box how long it this took, in decimal hours, and whether the output was as you expected or not.

For reference:
  1. Consider this code:
    def blorp(a):
        for i in range(a, a + 5):
            squarePlus = i * i + 1
            if squarePlus % 13 == 0:
                print("Oh no, we got unlucky: ", squarePlus)
                break
            print(i, "^2+1 =>", squarePlus)
        print("Done")
    
    On paper, figure out what this would print if we called blorp(3). Then, paste this code into Thonny and see what it actually outputs. Once you understand blorp(3), try running blorp(9) in Thonny.

  2. Consider this code:
    def gloop(a,b):
        i = a
        while i < b:
            print(i)
            if i % 3 == 0:
                i = i * 2 + 1
                continue
            i = i + 1
    
    On paper, figure out what this would print if we called gloop(2,9). Then, paste this code into Thonny and see what it actually outputs. Once you understand gloop(2,9), try running gloop(1,20) in Thonny.