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 “excuses.csv” in the Github repository Extra credit if you print the link to the story as well


In [6]:
import pandas as pd
import random

In [5]:
df = pd.read_csv("excuse.csv")
df


Out[5]:
excuse headline hyperlink
0 the fog was unexpected and did slow us down a bit De Blasio Blames 'Rough Night' and Fog for Mis... http://www.dnainfo.com/new-york/20141112/rocka...
1 we had some meetings at Gracie Mansion De Blasio 30 Minutes Late to Rockaway St. Patr... http://www.dnainfo.com/new-york/20150307/belle...
2 I had a very rough night and woke up sluggish De Blasio Blames 'Rough Night' and Fog for Mis... http://www.dnainfo.com/new-york/20141112/rocka...
3 I just woke up in the middle of the night and ... De Blasio Blames 'Rough Night' and Fog for Mis... http://www.dnainfo.com/new-york/20141112/rocka...
4 we had some stuff we had to do De Blasio 30 Minutes Late to Rockaway St. Patr... http://www.dnainfo.com/new-york/20150307/belle...
5 I should have gotten myself moving quicker De Blasio Blames 'Rough Night' and Fog for Mis... http://www.dnainfo.com/new-york/20141112/rocka...
6 I was just not feeling well this morning De Blasio Blames 'Rough Night' and Fog for Mis... http://www.dnainfo.com/new-york/20141112/rocka...
7 breakfast began a little later than expected De Blasio 15 Minutes Late to St. Patrick's Day... http://www.dnainfo.com/new-york/20150317/midto...
8 the detail drove away when we went into the su... Mayor de Blasio Is Irked by a Subway Delay http://www.nytimes.com/2015/05/06/nyregion/may...
9 we waited 20 mins for an express only to hear ... Mayor de Blasio Is Irked by a Subway Delay http://www.nytimes.com/2015/05/06/nyregion/may...
10 we need a better system Mayor de Blasio Is Irked by a Subway Delay http://www.nytimes.com/2015/05/06/nyregion/may...

In [35]:
random.choice(df['excuse'])


Out[35]:
'we had some meetings at Gracie Mansion'

In [36]:
def excuse_generator(name,location):
    #print("entered loop")
    name= name
    location= location
    return "Sorry"+ " " + name +" " + "I was late to"+ " " + location + " "+ "to meet you"+ " "+ random.choice(df['excuse'])

In [37]:
excuse_generator('Mercy','School')


Out[37]:
"Sorry Mercy I was late to School to meet you I just woke up in the middle of the night and couldn't get back to sleep"

In [38]:
pick_name= input("Choose a name")
pick_location= input("Choose a location")


Choose a namemercy
Choose a locationschool

In [39]:
excuse_generator(pick_name,pick_location)


Out[39]:
'Sorry mercy I was late to school to meet you we waited 20 mins for an express only to hear there were major delays'

In [ ]: