ANSWERS ALL CORRECT
What is the difference between a print and a return function? - Answer- Print functions
display an output on the screen, while return functions send a value back to where the
function is called. Functions with no return automatically return "None".
What is a pure function? - Answer- A function that has no side effects, does not print or
modify variables, and only returns a value.
What is this an example of, and what will the function return? Explain how this works.
def add(a, b):
return a + b
print(add(3, 5)) - Answer- Return function;
8;
The function is defined then called inside print, the function returned 8, and print()
displayed it.
What is incremental development, and what are the steps? - Answer- Building complex
functions step-by-step, and testing them as you go;
Write simple version
Test
Add Complexity
Test Again
Why do we use return in recursion? - Answer- We use return so each recursive call can
send its answer back to the previous call.
This allows the program to build the final result step-by-step.
If we don't use return, the function might run but we cannot use the result in
calculations.
Modulus Operator (%) - Answer- Returns the remainder after division
What is this an example of; and what does this return?
minutes = 105
hours = minutes // 60
remainder = minutes % 60
print(hours)
, print(remainder) - Answer- Modulus operator;
1
45
Boolean Expression - Answer- Expressions that evaluate to True or False
What is this an example of, and what does it return?
temperature = 60
result = temperature > 70
print(result) - Answer- Boolean expression; False
int -> Integer - Answer- A whole number that can be positive, negative, or zero
float -> Floating point - Answer- Numbers with a decimal point
str -> String - Answer- Sequence of characters, inside quotes
bool -> Boolean - Answer- True or False
• capital T/F
• no quotes
Boolean Comparisons - Answer- Comparisons that are either True or False
A == B - Answer- True if A is equal to B
A != B - Answer- True if A is not equal to B
What is this an example of, and what does it return?
x = 10
y=8
print(x > y)
z=x>y
print(z) - Answer- Boolean comparison;
True
True
Logical Operator - Answer- Combine boolean expressions: and, or, not
Logical Operator: and - Answer- Both cases must be true; x>0 and x<10 is True if x is
between 0 and 10
Logical Operator: or - Answer- At least one case must be true; x % 2 == 0 or x % 3 == 0
is True of x is divisible by 2 or 3
Logical Operator: not - Answer- Negates boolean; x > y is True if x is NOT greater than
y