Python: Functions Flashcards
What line of code can be used to return a variable inner_var from a function back to the piece of code that called the function?
return inner_var
What line of code will call force with a value of 10 for mass and a value of 9.81 for acceleration?
def force(mass, acceleration):
force_val = mass*acceleration
return force_val
force(10, mass=9.81)
force(mass=10, 9.81)
force(9.81, 10)
force(10, 9.81)
force(10, 9.81)
What happens when you call report()?
time = “3pm”
mood = “good”
def report():
print(“The current time is “ + time)
print(“The mood is “ + mood)
print(“Beginning of report”)
report()
Two Strings are printed: “The current time is 3pm” and “The mood is good”
Which variables can be called in the blank spot in this code:
counter = 0
def update():
new_counter = counter + 1
return new_counter
_______
Just counter.
How do you call a function called setup with no arguments?
setup()
Given the following function, what will produce the output “There is no greater agony than bearing an untold story inside you.”?
def quote(x):
print(“There is no greater agony than bearing “ + x + “ inside you.”)
quote(“an untold story”)
How do you call update with a new_value of 20?
def update(new_value = 10):
old_value = new_value
update(20)