In [1]:
def greet_user():
    """Display A simple greeting"""
    print("Hello")
greet_user()


Hello

In [2]:
def greet_user(username):
 """Display a simple greeting."""
 print("Hello, " + username.title() + "!")

greet_user('jesse')


Hello, Jesse!

In [3]:
def describe_pet(animal_type, pet_name):
 """Display information about a pet."""
 print("\nI have a " + animal_type + ".")
 print("My " + animal_type + "'s name is " + pet_name.title() + ".")

describe_pet('hamster', 'harry')


I have a hamster.
My hamster's name is Harry.

In [4]:
def describe_pet(animal_type, pet_name):
 """Display information about a pet."""
 print("\nI have a " + animal_type + ".")
 print("My " + animal_type + "'s name is " + pet_name.title() + ".")

describe_pet('hamster', 'harry')
describe_pet('dog', 'willie')


I have a hamster.
My hamster's name is Harry.

I have a dog.
My dog's name is Willie.

In [5]:
def describe_pet(animal_type, pet_name):
 """Display information about a pet."""
 print("\nI have a " + animal_type + ".")
 print("My " + animal_type + "'s name is " + pet_name.title() + ".")
describe_pet('abc','afg')


I have a abc.
My abc's name is Afg.

In [6]:
def get_formatted_name(first_name, middle_name, last_name):
 """Return a full name, neatly formatted."""
 full_name = first_name + ' ' + middle_name + ' ' + last_name
 return full_name.title()

musician = get_formatted_name('john', 'lee', 'hooker')
print(musician)


John Lee Hooker

In [7]:
def build_person(first_name, last_name):
 """Return a dictionary of information about a person."""
 person = {'first': first_name, 'last': last_name}
 return person
musician = build_person('jimi', 'hendrix')
print(musician)


{'first': 'jimi', 'last': 'hendrix'}

In [8]:
def build_person(first_name, last_name, age=''):
 """Return a dictionary of information about a person."""
 person = {'first': first_name, 'last': last_name}
 if age:
  person['age'] = age
 return person
musician = build_person('jimi', 'hendrix', age=27)
print(musician)


{'first': 'jimi', 'last': 'hendrix', 'age': 27}

In [ ]:
def get_formatted_name(first_name, last_name):
 """Return a full name, neatly formatted."""
 full_name = first_name + ' ' + last_name
 return full_name.title()
# This is an infinite loop!
while True:
 print("\nPlease tell me your name:")
 f_name = input("First name: ")
 l_name = input("Last name: ")

 formatted_name = get_formatted_name(f_name, l_name)
 print("\nHello, " + formatted_name + "!")


Please tell me your name:
First name: kamrna
Last name: tahir

Hello, Kamrna Tahir!

Please tell me your name:
First name: quit