Arithmetic/Conditionals
Loops/Lists
Dictionaries
Functions
Misc
100

This flow control statement loops through a set of statements if a test statement continues to evaluate to True.


What is an "if" statement?

100

Loops are used to execute code repeatedly. What is another word for this? 

What is iteration?

100

What do dictionary pairs consist of?

Keys and Values

100

What is the keyword that always precedes a function definition?

def

100

This operator "glues" two strings together. Give an example. 

What is the concatenation (+) operator?

200

What does the += operation do?

Write an equivalent statement to: x += 4

It adds assigns the variable to its original value plus the value to the right of the operation.

x += 4 ---> x = x + 4

200

What is a list? 

A list is a collection of values which are ordered and mutable. 

200

How do we iterate through the keys of a dictionary? How about the values?

Use dict_name.keys() or dict_name to iterate through the keys, and dict_name.values() to iterate through the values.

200

What is the difference between a print statement and a return statement?

You use print statements to display something on the console, while you use return statements in functions to output and store the result of the function call in a variable.

200

This character denotes the floor division operator.

What is the double forward slash (//) ?

300

What does the != operator mean? Give an example using numbers and its output.

It means "not equal".

Ex: 5 != 4 (TRUE)

300

When you know the number (or steps) of times you want to iterate which type of loop should you use?

What is a for loop?

300

What is displayed on the console? 


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

res = ""

for v in dict:

  res += (v + str(dict[v]))

print(res)

a1b2c3d4

300

What is displayed on the console? 


def mystery2(x):

  return x%2 


def mystery3(x):

  return x%3

  

def mystery(x):

  return mystery2(x) + mystery3(x)


print(mystery(100))

1

300

How do you generate a random number? What purpose does it have? 

You use the random library - random.randint(start, stop) 

You use it so that you can simulate real life where you won't know what values you will be given. 

400

What is the result of int("2") ** 3 ?

What is 8?

400

What does it mean for lists to be mutable? Give one example of how you can mutate a list. 

Mutable means that list values can be changed after they are created. 

list_name.append(value)

list_name[index] = value 

list1 += list2

list_name.pop()

400

What is stored in dict? 


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

for x in "abcd":

  dict[x] = dict[x] + 75%3 + 100%7

{'a': 3, 'b': 4, 'c': 5, 'd': 6}

400

What is displayed on the console? 


def mystery(a):

  mystery_val = 0 

  for i in range(len(a)):

    mystery_val = a[i]*(i+1) 

  return mystery_val


print(mystery([10, 20, 30, 40, 50]))

250

400

How do you take in user input in Python. What do you do if the input is a numerical value?

You use the input("Prompt") code. If it is a numerical value, you have to convert it into a float or an integer. 
500

Give a real life example of using a if - else if - else statement. 

Any valid example. 

500

What is the value of 'x' after the following Python code has completed executing?

x = 100

for n in range(1,5):

    x = x*n 

print (x)

What is 2400?

500

What is stored in dict? 


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

dict["pineapple"] = 20

dict["a"] = dict["a"]*100 + dict["pineapple"]

for x in "SWE":

  dict[x] = dict["b"]*dict["a"]

{'a': 120, 'b': 2, 'c': 3, 'd': 4, 'pineapple': 20, 'S': 240, 'W': 240, 'E': 240}

500

 What is displayed on the console? 


def mystery(x):

  mystery_val = {}

  count = 0

  for i in x:

    mystery_val[i] = count

    count += 1

  return mystery_val 


print(mystery("SWE++"))

{'S': 0, 'W': 1, 'E': 2, '+': 4}

500

Use a loop to count the number of times an "o" appears in the word "voodoo". 

word = "voodoo"

count = 0

for i in _______:

       if ________:

            count _______ 

print(count)

word = "voodoo"

count = 0

for i in word:

       if i == "o":

            count += 1