Functions

0.0(0)
Studied by 2 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/21

flashcard set

Earn XP

Last updated 7:26 PM on 11/24/22
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

22 Terms

1
New cards
scope
The _______ of a variable refers to the regions of the program where
that variable is valid, and can be accessed
2
New cards
a local variable
the variable that is not shared between functions
3
New cards
a global variable
a _______ variable is a variable defined throughout the program – anything in
the main code
4
New cards
5
5
5
def my_function():
print(a)

a = 5
print(a)
my_function()
print(a)
5
New cards
5
6
5
def my_function(x):
x += 1
print(x)

a = 5
print(a)
my_function(a)
print(a)
6
New cards
5
def F(a):
a += 3

a = 5
F(a)
print(a)
7
New cards
UnboundLocalError
def F():
a += 3

a = 5
F()
print(a)
8
New cards
10
def F(a):
print(a)

a = 5
b = 10
F(b)
9
New cards
8
def F():
global a
a += 3

a = 5
F()
print(a)
10
New cards
multiple, but if more than one it needs to be in a tuple.
otherwise, it needs to be a single "thing"
how many values can a function return?
11
New cards
the function immediately ends
after a value has been returned in a function.....
12
New cards
21
def twenty_one():
return 21

a = twenty_one()
print(a)
13
New cards
True
False
def is_three_more(a, b):
if a == b + 3:
return True

else:
return False

print(is_three_more(10, 7))
print(is_three_more(1, 5))
14
New cards
5
def F(a):
a += 1
return a
a += 10
return a

x = F(4)
print(x)
15
New cards
Toronto Ontario Canada
Orlando Florida USA
Houston Texas USA
Bryan Texas USA
def F(a="Bryan", b="Texas", c="USA"):
print(a, b, c)

F("Toronto", "Ontario", "Canada")
F("Orlando", "Florida")
F("Houston")
F()
16
New cards
TypeError: F() missing 1 required positional
argument: 'a'
"Parameters without a default value
must be specified"
def F(a, b="Texas", c="USA"):
print(a, b, c)

F()
17
New cards
1
2
def dosomething(a, b):
a += b
b = 7

x = 1
y = 2
dosomething(x, y)
print(x)
print(y)
18
New cards
1.0
2.0
def dosomething(a, b):
a += b
b = 7

x = 1.0
y = 2.0
dosomething(x, y)
print(x)
print(y)
19
New cards
Texas
Aggies
def dosomething(a, b):
a += b
b = 7

x = "Texas"
y = "Aggies"
dosomething(x, y)
print(x)
print(y)
20
New cards
[1, 2]
[2]
def dosomething(a, b):
a += b
b = 7

x = [1]
y = [2]
dosomething(x, y)
print(x)
print(y)
21
New cards
[1, 2, 3]
def dosomething(a):
a = [10, 11, 12]

x = [1, 2, 3]
dosomething(x)
print(x)
22
New cards
[10, 2, 3]
def dosomething(a):
a[0] = 10

x = [1, 2, 3]
dosomething(x)
print(x)