Or Else!
A key collection?!
Who wants the funk?
OOPs, very deCLASSe!
Bugging out
100

Keyword that starts a loop that runs while a condition is true.

What is a while loop?

100

The Python data structure that is ordered, mutable, and allows duplicates.

What is a list?

100

The keyword that declares or defines a function in Python.

What is def?

100

The expression that define a class named Dog.

What is:

class Dog:

   pass

100

The output of print(2 + 3 * 4)?

What is 14? 

200

The output of:
if 5 > 3: print("Yes")
else: print("No")

What is "Yes"?

200

The built-in data type that is like a list but immutable.

What is a tuple?

200

Write a function multiply that accepts 2 numerical arguments and returns the product of those arguments.

def multiply(num1, num2):

   return num1 * num2

200

A use case for __init__.

What is a constructor, which initializes a new object?

200

There is an indentation error in the code below, what is it?

if True:

print("Yes")

The print line must be indented under the if

300

Behavior that happens if you put break inside a for loop.

What is exits the loop immediately?

300

The expressions that returns 4

d = {'a': [1, 4], 'nums': {'num': 34, 'digit': 4}

What is: 


1. d['a'][-1]


2. d['nums']['digit']
300

What is a parameter vs an argument? How are they are related?

A parameter is variable in the definition of a function and an argument is a value passed when the function is called. Functions access argument as parameter in the order that they are received.

300

Create an instance of an existing class Dog, which expects a breed and a name.

goodGirl= new Dog("chihuahua", "chichi")

300

What happens if you try to do my_list[5] but my_list only has 3 elements?

An IndexError is thrown by the compiler

400

Translate the following pseudocode into Python:
A short statement that prints "Even" if n is divisible by 2, otherwise prints "Odd"

if n % 2:

   print("Even")

else:

   Print("Odd")

400

An expression that checks if a list "L" includes an element "x".

What is: x in L ?

400

How can a function use the returned value of another function? Give an example.

The outer function can return the inner function which has been called/invoked.

def outerFunc(): 

   return innerFunc() // assuming innerFunc is defined

400

What self refers to inside a class method? Show how it can be used in a method.

The instance or context on which the method is called.

def getName(self):

   return self.name

400

What is returned when this function is called: 

def show_me_output() :

    for i in range(2):

        print(i)

    else:

        print("Done")


None. Because the function has no return statement so by default the value None is returned.

500

The number of time will this print: 

for i in range(2): 

   for j in range(3): 

       print(i, j)

+100 if you include the output.

What is 6 times?

Output: (0,0), (0,1), (0,2), (1,0), (1,1), (1,2)

500

2 differences and 2 similarities between a set and a dictionary?

Similarities: both can be represented using brackets {}, collections, Neither allow duplicate elements (sets will remove duplications automatically), both are mutable

Differences: Set stores values only, but dictionaries store key/value pairs (property), empty sets can only be defined using the set() function, but objects can be defined as empty brackets or the dict() function, Sets are unordered but dictionaries are ordered.

500

Explain inheritance in Python and give a simple example. (Answer: class Child(Parent): … – child inherits methods/properties of parent)

When a child/sub class inherits methods and properties from a parent/super class.

class Parent:

   def get_family_name(self):

      return self.family_name

class Child(Parent):

first_child = new Child()

child_family_name = first_child.get_family_name()

500

What is the result of running this code:

A.

def foo(a, b=5, c):

    return a + b

print(foo(3))

print(foo(3, 2))


B.

def foo(a, b, c):

    return a + b

print(foo(3))

print(foo(3, 2))

A. SyntaxError: parameter without a default follows parameter with a default.

B. TypeError: foo() missing 2 required positional arguments: 'b' and 'c'