Expressions & Types
Conditions & Loops
Functions
Classes
Error Handling
100

Define a variable called 's' that contains a new empty set

s = set()

100

Write a simple (but correct) if/elif/else

i = input()

if i == 'y':

   print('yes')

elif i == 'n':

   print('no')

else:

   print('unknown')

100
[True or False] Functions can have optional parameters without specifying default values.

False

100

In UML, a [_______] is used to specify whether a Derived Class extends from a Base class

What's an arrow?

100

The name of the code block that guarantees that some code will be executed even if there is some error being raised is  [_______]

What is finally?

200
The operator used to perform the division of two numbers, and have the result be an integer

What's the double slash (//)?

200
Write a simple for loop that demonstrates how to use enumerate()

for index, value in enumerate([3, 4, 5]):

     print(f"{index}:{value}")

200

Names of the variables in local scope:

def count_dozens(num_apples):

    dozens = num_apples // 12

    remain = num_apples % 12

    return dozens, remain

app = int(input())

d, r = count_dozens(app)

What's num_apples, dozens, remain?

200

Draw UML for any two classes to demonstrate what a 'has-a' relationship looks like

<drawing using a diamond arrow>

200

The output of this code: 

def access(a_list, index, on_error): 

    try: 

        return a_list[index]

    except: 

        return on_error

print(access([0], 5, "Ouch"))

What is ouch?

300

Given a list called abc, define a variable named xyz that contains a set of values present in abc, eliminating duplicates. 

xyz = set(abc)

300

Use list comprehension to create a list of numbers 1 through 10 (inclusive) and store it in a new variable called nums. 

nums = [i for i in range(1, 11)]

300

Code that prints the global scope of a program

print(globals())

300

The problem with this code: 

class Alpha:

     def sub(self):

          print("Hello")

class Beta(Alpha): 

     def sub1(self):

          print("Howdy")

print(Alpha().sub1())

last line: class Alpha can't access derived class Beta's sub1() method. 

300

An example of code using a try/finally

def divide(a, b):

   try: 

      return a / b

  finally: 

     print("Done")

divide(5, 0)

400

Use the math module to compute the square root of a number provided by the user and print it. 

import math

print(math.sqrt(float(input())))

400

The value of x is [____]: 

x = False or not True or 4**2 >= 16 and "severe" > "serious"

True

400

The output of: 

def abc(x=1, y=2):

     print(y/x+2)

x=2

y=4

abc(y=x,x=y)

What's 2.5?

400

Define a class called Fork that derives from Utensil and contains two private attributes: size and color. The constructor for both classes (Fork and Utensil) has no parameters other than self

class Fork(Utensil): 

   def __init__(self):

          Fork.__init__(self)

          self.color = ""

          self.size = 0

400

The problem with this code: 

class Blank(Exception): 

     def __init__(self, msg): 

          Exception.__init__(self,msg)


The name of class Blank doesn't end with suffix 'Error' as promised between Python developers. 

M
e
n
u