In [32]:
import csv
import random
In [69]:
# opens and reads excuse.csv
reader = csv.reader(open('excuse.csv','r'), delimiter=',')
# skips headers
next(reader)
# makes empty list
data = []
# make tuples from csv file, append tuple to list
for rows in reader:
excuse = rows[0]
hyperlink = rows[2]
pair = excuse, hyperlink
data.append(pair)
In [ ]:
# takes a name and location
name = input('Enter a name')
location = input('Enter a location')
# prints a random excuse and its source(hyperlink)
if name and location:
random_pair = random.choice(data)
print('Sorry',name,'that I was late to',location,'to meet you;',random_pair[0])
print('This excuse can be found in this article:',random_pair[1])