Fun with Functions

The questions below are due on Sunday July 07, 2024; 10:00:00 PM.
 
You are not logged in.

Please Log In for full access to the web site.
Note that this link will take you to an external site (https://shimmer.mit.edu) to authenticate, and then you will be redirected back to this page.

Function Output Types

For each of the following functions (which take either ints or floats as input), specify the type of the output generated by that function, assuming that valid input is provided (no Python error occurs).

If it can be either an int or a float, use int or float.

Link to relevant section of reading

def a(x):
    return x+1

Result: 

def b(x):
    return x+1.0

Result: 

def c(x,y):
    return x > y

Result: 

def e(x,y):
    x + y - 2

Result: 

Using Functions

Assuming the functions from above (copied below) have been defined, provide the value of the expressions below. Be careful of types, and of Python's capitalization!

If evaluating the expression would cause an error, write error in the box. If the value of an expression is a function, write function in the box.

def a(x):
    return x+1

a

a(6.0)

a('7')

a(a(a(6)))

def b(x):
    return x+1.0

b(None)

b()

def a(x):
    return x+1
def b(x):
    return x+1.0
def c(x,y):
    return x > y

c(a(1), b(1))

def e(x,y):
    x + y - 2

e(1,2)

def b(x):
    return x+1.0
def f(x,y):
    return f'{x+b(y)=}'

Link to relevant section of reading

f(3,4)

Next Exercise: Functions and Scope

Back to exercises