Random
Functions
Branching
Looping
Lists &
Indexing
100

This term is used to describe the type of data found here: 'hello'

string

100

Define what a function is.

A function is a group of statements that perform a specific task when called. They help avoid repetition and make code re-usable.

100

What is wrong with the following statement and why?

if x > 10 and <15:


if x > 10 and x <15:

Your condition has to be defined so that it is being checked against a variable.

100

Build up a simple FOR loop. Tell me how you did it.

for number in range(6):

        print(num)

100

What is each value in a sequence called?

An element or item.
200

How do I create a multi-line string? Why are they useful?

Use triple quotes - useful in situations where you want to have something printed on multiple lines and do not want to use escape characters.

200

What are the three main parts of a function?

function header

parameters

function body

200

What are 2 rules when creating branching?

1. make sure you use a colon

2. use an elif statement only if there are more than two branching directions

3. the second that a condition is true, the branching ends (aka the remaining statements are not checked)

200

Build up a while loop. Tell me how you did it.

while x < 10:

       print(x)

       x = x + 1

       

200

Describe how to index or negative index.

list[index] = item at index

starting from 0 for positive

starting from -1 for negative

300

What is a variable?

A Python variable is a reserved memory location to store values. 

variable = value

300

Whats wrong with this function?

def big_or_small(num1, num2)

      return num1 > num2

There is no colon after the function header.

300

Why would I use an if-if-if block versus an if-elif-else block?

In order to test multiple conditions at once - you might have multiple that are true and not have an "else" alternative.

300

Explain why we use counters or booleans for while loops.

Because the condition in the while loop beginning has to be checked in order to determine when to stop looping. Without a counter or a boolean check, the loop would be infinite.

300

How would I add an item into the middle of a list? How would I replace an item in the middle of a list?

Add: using built in function .insert(index position, item to add)

replace: using indexing

400

If I get user input, what data type is it automatically stored as? 

How do I change that data type?

A string. 

Using int() or float() built-in functions. 

400

List at least 2 rules about defining functions

1. Always indent evenly

2. End with a blank line

3. End the function header with a colon

4. Choose appropriate parameter names

5. Choose an appropriate function name

400

What is branching?

Creating multiple sets of instructions, which allows the program to have choice based on conditions

400

Give me two situations where you would use a for loop, and two situations where you would use a while loop.

For: 1.when looping through a range of numbers

2. when looping through a list/array

While: 1. When you have a condition to check

2. When you are getting user input


400

what does the following code do?:

num_list = [1, 4, -5, 8, -9, -2, 3]

evens = []

for num in num_list:

    if num % 2 == 0:

               evens.append(num)


loops through the list of numbers, checks if each number divided by 2 has a remainder of 0 (making it an even number), and if this condition is true adds that number to the new list called evens

500

What is abstraction and why is it important?

Process of ignoring the details and finding the common ideas. An important concept to understand for function definition. You are creating a set of rules, with parameters that need to be included in order for the function to work. You want it to be able to be used over and over again, with different input values, so the function has to focus on a common idea versus specific details. 

500

What is the difference between parameters and arguments?

Parameters: These are placeholders that describe what type of information needs to be passed to the function in order for it to work. 

Arguments: These are the actual values being input into the function when the function is called to action

Remember: Not all functions need parameters - but if your function has parameters, order matters!

500

What is a nested if statement and why are they useful?

A nested if statement is an if-statement within another if/else-statement. They are useful when you have a condition that is dependent on other if statements being true - they will only execute when another condition is true.

500

What is the difference between a FOR loop and a WHILE loop?

The For loop is used when we already know the number of iterations. The while loop is used when the number of iterations is not exactly known.

500

Tell me what these statements mean:

my_list[:5]

my_list[2:]

my_list[3:9]

my_list[6]

my_list[-2:-5]

my_list[:-3]

From the start of the list up to but not including index 5.

From index 2 up to the end of the list.

From index 3 up to but not including index 9.

The item at index 6.

From the second last index up to but not including the index at position -5.

From the beginning of the list up to but not including the third index from the end of the list.

M
e
n
u