Loops
Misc.
Strings/Lists
OOP/Classes
100

The output of this code:

sum = 0
for i in range(12,2,-2):
    sum+=i
print sum

What is 40?

100

Output shown to console:

a = "CS303E "

b = 11

print (a + b)

What is an error? (specifically, compile error)

100

Output of this code:

List=[1,6,8,4,5]
print List[-4:]

What is [6, 8, 4, 5]?

100

The error in this code:

class Test:
     def __init__(self, s):
         self.s = s
 
     def print(self):
         print(self.s)

msg = Test()
msg.print()

What is the constructor is not passed an argument?

200

Tthe following loop is executed this many times:

i=100
while(i<=200):
    print i
    i+=20

What is 6?

200

Find the error:

x= int(“Enter value of x:”)
for in range(0,10):
     if x=y:
          print(x + y)
     else:
          print(x ‐ y)

What is x=y? (correction would be x==y)

200

Output of this code:

def f(value, values):
    v = 1
    values[0] = 44
t = 3
v = [1, 2, 3]
f(t, v)
print(t, v[0])

What is 3 44?

200

Output of the following code:

class Sales:
    def __init__(self, id):
        self.id = id
        id = 100

val = Sales(123)
print (val.id)

What is 123?

300

Output:

n=11
for i in range(2,n//2):
    if n%i!=0:
        print("Hello")
    else:
        print("Goodbye")

What is:

Hello

Hello

Hello

300

a = True

b = False

c = False

if not a or b:

    print (1)

elif not a or not b and c:

    print (2)

elif not a or b or not b and a:

    print (3)

else:

    print (4)

What is 3?

300

Output of the following code:

arr = [1, 2, 3, 4, 5, 6]
for i in range(1, 6):
    arr[i - 1] = arr[i]
for i in range(0, 6):
    print(arr[i], end = " ")

What is 2 3 4 5 6 6?

300

class A:
    def __init__(self):
        self.calcI(30)
        print("i from A is", self.i)

    def calcI(self, i):
        self.i = 2 * i;

class B(A):
    def __init__(self):
        super().__init__()
       
    def calcI(self, i):
        self.i = 3 * i;

b = B()

What is i from A is 90?

M
e
n
u