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”)


In [1]:
import pandas as pd

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

In [3]:
df.head()


Out[3]:
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...

In [4]:
import random

In [5]:
def random_excuse(line):
    excuse = random.choice(line)
    return excuse

random_excuse(df['excuse'])


Out[5]:
'I should have gotten myself moving quicker'

In [7]:
name = input("Enter your name: ")


Enter your name: Hon

In [8]:
location = input("Where are you headed? ")


Where are you headed? The international space center

In [10]:
print("Sorry", name, "I was late to", location, "because", random_excuse(df['excuse']))


Sorry Hon I was late to The international space center because we had some stuff we had to do

In [ ]:
#Question: How to get the corresponding hyperlink if it's random?