solutions

Return the type of a given value

Write a function using if statements that takes a value, and returns the type of that particular value. Example:

which_type(2) == 'integer'
which_type("cookies, now!") == 'string'
which_type(False) == 'boolean'
which_type(42.0) == 'float'

Hint: Be mindful of control flow. Remember that booleans in python are tricky.

Test Cases

test type boolean - Run Test

def test_type_boolean():
    assert which_type(True) == 'boolean'

test type float - Run Test

def test_type_float():
    assert which_type(3.14) == 'float'

test type string - Run Test

def test_type_string():
    assert which_type('squirrel') == 'string'

test type int - Run Test

def test_type_int():
    assert which_type(42) == 'integer'