Answers

1)

In [1]:
inventory = ['pens', 'paper', 'staples', 'paperclips', 'tape', 'crayons', 'highlighters']
def do_we_have(item):
    """Prints out whether or not the item is in stock."""
    if item in inventory:
        print('We have', item, 'in stock!')
    else:
        print('We are out of', item)
In [2]:
do_we_have('staples')
do_we_have('paper')
do_we_have('pencils')
We have staples in stock!
We have paper in stock!
We are out of pencils

3)

In [3]:
def greeter(name):
    """Prints a customized greeting for a person's name."""
    if len(name) < 5:
        print("Hello " + name + "! Is that your full name?")
    elif len(name) <= 8:
        print("Hello " + name + "! That's a lovely name!")
    else:
        print("Hello " + name + "! Can I call you " + name[:3] + "?")
In [4]:
greeter("Katy")
greeter("Manuel")
greeter("Wendell")
greeter("Wendell Smith")
greeter("Katy Krueger")
Hello Katy! Is that your full name?
Hello Manuel! That's a lovely name!
Hello Wendell! That's a lovely name!
Hello Wendell Smith! Can I call you Wen?
Hello Katy Krueger! Can I call you Kat?