Python: Functions Flashcards

1
Q

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?

A

return inner_var

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

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)

A

force(10, 9.81)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

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()

A

Two Strings are printed: “The current time is 3pm” and “The mood is good”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Which variables can be called in the blank spot in this code:

counter = 0

def update():
new_counter = counter + 1
return new_counter

_______

A

Just counter.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do you call a function called setup with no arguments?

A

setup()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

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.”)

A

quote(“an untold story”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do you call update with a new_value of 20?

def update(new_value = 10):
old_value = new_value

A

update(20)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly