2014-04-08 - HW

posted Apr 8, 2014, 5:24 AM by Samuel Konstantinovich   [ updated Apr 8, 2014, 8:56 AM ]
Homework: Complete the problems you didn't finish in class. You can write it in your notebooks, it is not required of you to print it.

Goal: Practice! + Test Internet.

Complete these problems on looseleaf:
1. What prints when the code is run?
H=[1,3,9,5,2]
for x in H:
    x=x**2
print H

2. What prints when the code is run? 
Y=[4,0,3,1,2]
for i in range(len(Y)-1):
    Y.append(Y.pop(0))
print Y

3. What prints when this code is run?
G=[2,3,1,0,4]
for i in range(len(G)):
    G[G[i]]=i
print G

4. What will print when you run this code?
def f(x):
   y = 2 * x + 1
   print y
z = f(3)
print z

5a. What is contained in y?
x=[]
for i in range(1,11,2):
    x+=[i]
y=x[1:len(x)-1]

5b. Using y from above, what is printed?
for j in y:
    print j*chr(ord('a')+j)


6. Copy the code, and write the corrections to the right of the code: (syntax errors only)
def miste(r,e)
    x=[]
    while r < e
        x.append(r)
        r=r+1
    y=[]
    1=i
    while i<=len(x):
        x[-i]*=e
        if i%2=0:
            y=y+i
        i.append(1)
    print x,y
Comments