Quiz 4 Flashcards
A definition of a function has what 2 parts
- The head
- The Block
def fun_name():
return statement
Why must you indent the statements in a block
so that the interpreter(Python) knows that statements are apart of the block
What are variables that receive pieces of data in a functions called?
Parameters
What does the phrase “calling a function” mean?
execute the program
When a function is executing, what happens when the end of the function’s black is reach?
Returns to where the function was called
What is a variable’s scope?
a variable is only defined within the function that it is found
Write a statement that calls the function: def message(): print("I am glad it is tuesday")
message()
Write a statement that calls the function: def show_sum(num1,num2): result = num1 + num 2 print (result)
show_sum(1,3)
Write a statement that calls the function: def area(width,length): return width*length
area(4,30)
Write a statement that calls the function: def area(width,length): return width*length
area(4,30)
Write a function called factorial that will take an integer as a parameter, and return the factorial of that number. You must use a for loop
def factorial(num): total = 1 for number in range (1,num+1): total = total*number return total
Write a statement that calls the function: def show_double(number): result = number*2 print(result)
show_double(5)
Def calculate_circumference(num1,num2): circumference = 2*num1*num2 return circumference 1) What is the name of the function? 2) What does the function do? 3) Given the function definition, what will the following statement display print(calculate_circumference(3.1459,0.5)
1) calculate_circumference
2) Calculate the circumference of a 4 sided shape or circle
3) 3.1459
Write a function named times_ten. The function should accept an argument and display the product of its argument multiplied times 10.
def times_ten (number): print(number*10)
What will be displayed? def main(): x = 1 y = 3.4 print(x, y) change_us(x, y) print(x, y) def change_us(a, b): a = 0 b = 0 print(a, b)
1, 3.4
0, 0
1, 3.4