Assignment 2

  • Create your own version of the Mayoral Excuse Machine in Python that takes in a name and location, selects an excuse at random and prints an excuse("Sorry, Richard, I was late to City Hall to meet you, I had a very rough night and woke up sluggish")

  • Use the "excuse.csv" in the Github repository

  • Extra credit if you print the link to the story as well


In [23]:
import pandas as pd
import random

In [9]:
df = pd.read_csv('data/excuse.csv')

In [17]:
df['excuse']


Out[17]:
0     the fog was unexpected and did slow us down a bit
1                we had some meetings at Gracie Mansion
2         I had a very rough night and woke up sluggish
3     I just woke up in the middle of the night and ...
4                        we had some stuff we had to do
5            I should have gotten myself moving quicker
6              I was just not feeling well this morning
7          breakfast began a little later than expected
8     the detail drove away when we went into the su...
9     we waited 20 mins for an express only to hear ...
10                              we need a better system
Name: excuse, dtype: object

In [22]:
excuse_list=pd.Series.tolist(df['excuse'])
name_list = ['Leonardo', 'Donatello', 'Michelangelo', 'Raphael']
location_list = ['Kitchen', 'Bathroom', 'Livingroom', 'Closet']

In [34]:
def random_name():
    return random.choice(name_list)
def random_location():
    return random.choice(location_list)
def random_excuse():
    return random.choice(excuse_list)

In [40]:
def mayoral_excuse_machine():
    return "Sorry, " + random_name() + ", I was late to " + random_location() + " to meet you, " + random_excuse() + '.'

In [41]:
mayoral_excuse_machine()


Out[41]:
'Sorry, Donatello, I was late to Bathroom to meet you, we waited 20 mins for an express only to hear there were major delays.'