Code Trace
Concepts(answer in question)
Error check
dictionaries
Misc(answer in question)
100

foo = 1

bar = 0

for i in range(5):

    print(foo)

    bar = foo

    foo = bar


1

1

1

1

1

100
with open("file.txt", "r") as file:

What line of code opens a file with read only privileges?

100

s = 'i am code'

for i in s;

   print(i)

print(s)

for i in s:

: instead of ;

100

key and value pair

What does a dictionary store?

100

A library with multi-dimensional arrays that supports linear algebra formalism

What is numpy?

200

d = {'a':1, 'b':2, 'c':3, 'd': 4}

d['e'] = 5

print(d.keys())

[a,b,c,d,e]

200

The ability to change an object from one type to another type

What is Polymorphism?

200

x = 0

while i < 10:

   print(x)

i is not defined

200

d = {'a': ['b','c'], 'b':['a','c'], 'c':[3,4]}

output: a

print(d['b'][0])

200

import Matplotlib.pyplot as plt

What line of code allows us to use the Matplotlib library

300

d = {'a':1, 'b':2, 'c':3, 'd': 4}

d['a'] = 10

d['e'] = 11

for i in d.keys():

    print(d[i])

10

2

3

4

11

300
with open('output.txt', 'a') as outputfile:

What line of code opens a file with appending privilages?

300

define fun(var1):

   print(F"The variable is {var1}")


def not define

300

d = {'a': ['b','c'], 'b':['a','c'], 'c':[3,4]}

d['d'] = [5, 6]

d['e'] = ['5','6']

output: [5,6]


print(d['d'])

300

file = 'input.txt'

try:

   input_file = open(file, "r")

   print("first line of the file: " + input_file.readline())

except IOError:

   print("File Open Error")

What is an example of Exception Handling?

400

class Bird(object):

   def __init__(self, w):

      self.__weight = w

   def getWeight(self):

      return str(self.__weight) + 'ounces'

   def getColor(self):

      raise NotImplementedError{'Method color not implemented'}

b1 = Bird(5.0)

b1.getColor()

b1.getWeight()

Method color not implemented

5.0

400

The blueprint vs the completed version based on the blueprint

What is the difference between Class and Instance

400
def foo(num):

   for i in range(num):

   print(i)

   print("done")

print(i) should be indented

400

d = {'a':1, 'b':2, 'c':3}

output: 2

print(d['b'])

400

import random as r

print(r.randint(0, 100))

How do you write a random number generator using the random library?

500

s = 'I am a CS major'

d = {}

for i in s:

    if i in d:

      d[i] += 1

   else:

      d[i] = 1

print(d)



{'a': 3, 'I': 1, ' ': 4, 'm': 2, 'C': 1, 'S': 1, 'j': 1, 'o': 1, 'r': 1}

500
self.__variablename

How do you make a member of a class private?

500

include random

l = ['blue', 'red', 'yellow']

print(random.choice(l))

include should be import

500

d = {'a':1, 'b':2, 'c':3}

Add 'd' : 4

d['d'] = 4

500

strings, lists, tuples, and numerical values

Which of the following types can be used as a key in Python dictionaries?