Happy Birthday

In [5]:
def main():
    print("Happy birthday to you!")
    print("Happy birthday to you!")
    print("Happy birthday, dear Fred...")
    print("Happy birthday to you!")    
In [6]:
main()
Happy birthday to you!
Happy birthday to you!
Happy birthday, dear Fred...
Happy birthday to you!
In [7]:
def happy():
    print("Happy birthday to you!")
In [8]:
def main2():
    happy()
    happy()
    print("Happy birthday, dear Fred...")
    happy()    
In [9]:
main()
Happy birthday to you!
Happy birthday to you!
Happy birthday, dear Fred...
Happy birthday to you!
In [10]:
singFred = main2
In [11]:
singFred()
Happy birthday to you!
Happy birthday to you!
Happy birthday, dear Fred...
Happy birthday to you!
In [12]:
def singLucy():
    happy()
    happy()
    print("Happy birthday, dear Lucy...")
    happy()
In [13]:
singFred()
print()
singLucy()
Happy birthday to you!
Happy birthday to you!
Happy birthday, dear Fred...
Happy birthday to you!

Happy birthday to you!
Happy birthday to you!
Happy birthday, dear Lucy...
Happy birthday to you!
In [14]:
def sing(person):
    happy()
    happy()
    print("Happy birthday, dear {0}...".format(person))
    happy()
In [15]:
sing
Out[15]:
<function __main__.sing>
In [16]:
sing()
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-16-5e3bdb313197> in <module>()
----> 1 sing()

TypeError: sing() missing 1 required positional argument: 'person'
In [33]:
sing("Fred", "Johnson")
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-33-15f9588de3a6> in <module>()
----> 1 sing("Fred", "Johnson")

TypeError: sing() takes 1 positional argument but 2 were given
In [34]:
sing("Fred Johnson")
Happy birthday to you!
Happy birthday to you!
Happy birthday, dear Fred Johnson...
Happy birthday to you!
In [ ]:
sing("Lucille Ball")
In [17]:
def main():
    for name in ["Fred Johnson", "Lucille Ball"]:
        sing(name)
        print()
In [18]:
main()
Happy birthday to you!
Happy birthday to you!
Happy birthday, dear Fred Johnson...
Happy birthday to you!

Happy birthday to you!
Happy birthday to you!
Happy birthday, dear Lucille Ball...
Happy birthday to you!

In [31]:
def main():
    file = open("/Users/Presenter/Desktop/census-dist-female-first.txt")
    data = file.readlines()
    
    for line in data[0:10]:
        parts = line.split()
        name = parts[0]
        name = name.title()
        sing(name)
        print()
In [32]:
main()
Happy birthday to you!
Happy birthday to you!
Happy birthday, dear Mary...
Happy birthday to you!

Happy birthday to you!
Happy birthday to you!
Happy birthday, dear Patricia...
Happy birthday to you!

Happy birthday to you!
Happy birthday to you!
Happy birthday, dear Linda...
Happy birthday to you!

Happy birthday to you!
Happy birthday to you!
Happy birthday, dear Barbara...
Happy birthday to you!

Happy birthday to you!
Happy birthday to you!
Happy birthday, dear Elizabeth...
Happy birthday to you!

Happy birthday to you!
Happy birthday to you!
Happy birthday, dear Jennifer...
Happy birthday to you!

Happy birthday to you!
Happy birthday to you!
Happy birthday, dear Maria...
Happy birthday to you!

Happy birthday to you!
Happy birthday to you!
Happy birthday, dear Susan...
Happy birthday to you!

Happy birthday to you!
Happy birthday to you!
Happy birthday, dear Margaret...
Happy birthday to you!

Happy birthday to you!
Happy birthday to you!
Happy birthday, dear Dorothy...
Happy birthday to you!

In [36]:
def sing2(first, last):
    happy()
    happy()
    print("Happy birthday, dear {0} {1}...".format(first, last))
    happy()
In [37]:
sing2("Fred", "Johnson")
Happy birthday to you!
Happy birthday to you!
Happy birthday, dear Fred Johnson...
Happy birthday to you!
In [ ]: