Unit 2 Flashcards

1
Q

What is a procedure?

A

A procedure takes in inputs, does some processing, and produces outputs.

A procedure is a way to package code so it can be reused with different inputs. Also known as functions, procedures enable you to abstract code from its inputs.

def ():

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is control in programming?

A

Control is a way to have the computer execute different instructions depending on the data rather than just executing instructions one after the other.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What do “if statements” allow you to do?

A

“if statements” allow you to write code that executes differently depending on the test expression.

if :

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What do “while loops” allow you to do?

A

“while loops” provide a convenient way to repeat the same operation many times.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is procedural abstraction?

A

Procedural abstraction is a way to write code one time that works on a wide range of different data values. By turning code into a procedure, you can use the same code over and over with different inputs to produce different outputs.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How to you make a procedure produce outputs with Python?

A

Producing outputs finishes a procedure. To do this, the return statement is used. A return statement can have any number of expressions. The values of these expressions are the out puts of the procedure.

return , , . . .

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How does a return statements with no expression behave?

A

A return statement with no expressions means that the procedure produces no output. This is useful for certain situations, such as where when the procedure is used for the effect from the operations rather than the output produced by the procedure itself.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

In what way can procedures be thought of as mathematical functions?

A

Think of procedures as something that maps inputs to outputs. This is why procedures are often referred to as functions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Why are procedures an important concept?

A

Procedures are a very important concept and the core of programming is breaking problems into procedures and implementing those procedures.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What does code need to be able to do to behave differently based on changing inputs?

A

To make decisions, code needs to be able to make comparisons, which will give your code a way to test inputs and decide what to do.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What operators does Python use for making comparisons?

A

Greater than
= Greater than or equal to
== Equal to
!= Not equal to

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What syntax is used to make comparisons with Python and what is the output?

A

Pythons operators work on numbers, for example:

The output of a comparison is a Boolean: True or False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What clause to the “if statement” can be used to provide an alternative block of code to execute if the test expression is false?

A

The “else” clause can be used to execute an alternative block of code if the “if statement’s” test expression returns false.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the test expression of an “if statement”?

A

The test expression determines whether to execute the block inside the if statement or the block inside the else statement.

The test expression is a statement that is evaluated by the code. The procedure executes different code based on the different outputs of the evaluation of the truth statement.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the “or expression”? How does it operate?

A

The “or expression” gives the logical or (disjunction) or two operands. If the first expression evaluates to True, the value is True and the second expression is not evaluated. If the value of the expression evaluates to False then the value of the or is the value of the second expression.

or

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is a loop? What is the “while loop”?

A

Loops are a way of executing a selection of code over and over.

The “while loop” is a common loop and similar to the “if statement” in that it evaluates a test expression and changes its action based on certain outputs of the evaluation of the test expression.

while :

17
Q

How does a “while loop” operate?

A

If the test expression for a while loop evaluates to True, the block is executed. Then the loop returns to reevaluate the test expression and see if the evaluation output has changed based on any changes that have occurred since or because of the execution of the previous loop. If it still evaluates to true, the block is again executed, and again returns to reevaluate the test expression until the the evaluation returns False. Once it returns False, execution jumps to the next statemetnt

18
Q

What does “break” let you do?

A

Break gives you a way to break out of a loop, even if the test condition is true. The typical structure of a loop with a break looks like:

while :
<code>
if :
break # stop executing the while loop</code>

The break statement will jump out of the loop the the </code>

19
Q

What is multiple assignment?

A

Multiple assignment is where you assign multiple values on the left side of an assignment statement. With multiple assignment, you can assign any number of names separated by commas, an equal sign and then any matching number of expressions separated by commas. The first name is assigned to the first expression and so on.

, , . . . = , , . . .