Chapter 5 and 6 Flashcards
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) main()
1 3.4
0 0
1 3.4
def class_function(a, b, c)
d = (a+c) /b print(d)
def my_function(a, b, c): d = (a + c) / b print(d) a. Write a statement that calls this function and uses keyword arguments to pass 2 into a, 4 into b, and 6 into c. b. What value will be displayed when the function call executes?
What will be the value displayed when this function call is executed?
2.0
Look at the following function header: def my_function(a, b, c):
my_function(3, 2, 1)
When this call executes def my_function(a, b, c): Now look at the following call to my_function: my_function(3, 2, 1) What value will be assigned to a? What value will be assigned to b? What value will be assigned to c?
3 passed to a
2 passed to b
1 passed to c
Write a statement that generates a random number in the range of 1 through 100 and assigns it to a
variable named rand.
rand = random.randint(1,100)
The following statement calls a function named half,
which returns a value that is half that of the argument.
(Assume the number variable references a float value.)
Write code for the function: result = half (number)
def half (number): return number/2
A program contains the following function definition: def cube (num) : return num num num Write a statement that passes the value 4 to this function and assigns its return value to the variable result.
result=cube(4)
Write a function named times_ ten that accepts
a number as an argument.
def times_ten(number):
When the function is called, it should return the value of
its argument multiplied times 10.
return (number) *10
get_first_name that asks the
user to enter his or her first name, and returns it.
def get_first_name(): first_name=input('Enter your first name: ') return(first_name)
def main():
print("The answer is", magic(5))
def magic(num):
answer = num + 2 * 10 return answer
main()
The function get_num() is expected to return a value for num1 and for num2.
A function definition specifies what a function does and causes the function to execute.
false
A local variable can be accessed from anywhere in the program.
false
def main(): print("The answer is", magic(5)) def magic(num): answer = num + 2 * 10 return answer main()
25