Unit 2 Flashcards
What is a procedure?
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 ():
What is control in programming?
Control is a way to have the computer execute different instructions depending on the data rather than just executing instructions one after the other.
What do “if statements” allow you to do?
“if statements” allow you to write code that executes differently depending on the test expression.
if :
What do “while loops” allow you to do?
“while loops” provide a convenient way to repeat the same operation many times.
What is procedural abstraction?
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 to you make a procedure produce outputs with Python?
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 does a return statements with no expression behave?
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.
In what way can procedures be thought of as mathematical functions?
Think of procedures as something that maps inputs to outputs. This is why procedures are often referred to as functions.
Why are procedures an important concept?
Procedures are a very important concept and the core of programming is breaking problems into procedures and implementing those procedures.
What does code need to be able to do to behave differently based on changing inputs?
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.
What operators does Python use for making comparisons?
Greater than
= Greater than or equal to
== Equal to
!= Not equal to
What syntax is used to make comparisons with Python and what is the output?
Pythons operators work on numbers, for example:
The output of a comparison is a Boolean: True or False
What clause to the “if statement” can be used to provide an alternative block of code to execute if the test expression is false?
The “else” clause can be used to execute an alternative block of code if the “if statement’s” test expression returns false.
What is the test expression of an “if statement”?
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.
What is the “or expression”? How does it operate?
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