Module 4: Functions, Tuples, Dictionaries, Exceptions, and Data Processing Flashcards

1
Q

What error type do you get when you invoke a function before it’s defined?
Example:
~~~
hi()
def hi():
print(“hi!”)
~~~

A

NameError

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

What error type do you get when you invoke a function with an unknown variable?
Example:
~~~
def hi():
print(“hi”)
hi(5)
~~~

A

TypeError: hi() takes 0 positional arguments but 1 was given

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

What output do you get when you execute the following code:
~~~
def adding(a, b, c):
print(a, “+”, b, “+”, c, “=”, a + b + c)
adding(3, a = 1, b = 2)
~~~

A
TypeError: adding() got multiple values for argument 'a'
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What output do you get when you execute the following code:
~~~
def subtra(a, b):
print(a - b)
subtra(a=5, 2)
~~~

A

SyntaxError: positional argument follows keyword argument

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
def add_numbers(a, b=2, c):
    print(a + b + c)

add_numbers(a=1, c=3)
A

SyntaxError: non-default argument follows default argument

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

What output do you get when you execute the following code:
~~~
def strange_function(n):
if(n % 2 == 0):
return True
print(strange_function(2))
print(strange_function(1))
~~~

A

True
None

By default a function returns None

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