Module 4: Functions, Tuples, Dictionaries, Exceptions, and Data Processing Flashcards
What error type do you get when you invoke a function before it’s defined?
Example:
~~~
hi()
def hi():
print(“hi!”)
~~~
NameError
What error type do you get when you invoke a function with an unknown variable?
Example:
~~~
def hi():
print(“hi”)
hi(5)
~~~
TypeError: hi() takes 0 positional arguments but 1 was given
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)
~~~
TypeError: adding() got multiple values for argument 'a'
What output do you get when you execute the following code:
~~~
def subtra(a, b):
print(a - b)
subtra(a=5, 2)
~~~
SyntaxError: positional argument follows keyword argument
def add_numbers(a, b=2, c): print(a + b + c) add_numbers(a=1, c=3)
SyntaxError: non-default argument follows default argument
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))
~~~
True
None
By default a function returns None