Dec-03-2019, 05:42 AM
#Program is written in python
from datetime import date
def calculateAge(birthDate):
today = date.today()
age = today.year - birthDate.year - ((today.month, today.day) < (birthDate.month, birthDate.day))
return age
def getDiscount(age):
discount = 0
if(18 <= age <= 25):
discount = 20
elif(26 <= age <= 35):
discount = 15
elif(36 <= age <= 45):
discount = 10
elif(46 <= age <= 60):
discount = 5
elif(60 <= age):
discount = 25
return discount
file = open("cusoumers.txt", "r")
for x in file:
data = x.split(",")
name = data[0]
street = data[1]
city = data[2]
state = data[3]
dob = list(map(int, data[4].split("/")))
pet= data[5].rstrip("\n")
age = calculateAge(date(dob[2],dob[1],dob[0]))
discount = getDiscount(age)
Animals = ["Cat","Dog","Horse","Fish"]
vendors = ["Bertha's Kitty Boutique","K9 Supplies","Saddle & Tack Shoppe","Aquariums 'N' Stuff","Pet-R-Us"]
if(pet in Animals):
vendorIndex = Animals.index(pet)
else:
vendorIndex = 4
reqVendor = vendors[vendorIndex]
f= open(name+"_formLetter.txt","w+") #saving the file name with the <name>_formLetter.txt format
f.write(name+"\n")
f.write(street+"\n")
f.write(city+",")
f.write(state+"\n\n")
f.write("Dear Valued Customer:\n\n")
f.write("Happy Birthday! You are eligible for a "+str(discount)+"% discount at")
f.write(reqVendor+".\n\nHappy shopping,\n")
f.close()
from datetime import date
def calculateAge(birthDate):
today = date.today()
age = today.year - birthDate.year - ((today.month, today.day) < (birthDate.month, birthDate.day))
return age
def getDiscount(age):
discount = 0
if(18 <= age <= 25):
discount = 20
elif(26 <= age <= 35):
discount = 15
elif(36 <= age <= 45):
discount = 10
elif(46 <= age <= 60):
discount = 5
elif(60 <= age):
discount = 25
return discount
file = open("cusoumers.txt", "r")
for x in file:
data = x.split(",")
name = data[0]
street = data[1]
city = data[2]
state = data[3]
dob = list(map(int, data[4].split("/")))
pet= data[5].rstrip("\n")
age = calculateAge(date(dob[2],dob[1],dob[0]))
discount = getDiscount(age)
Animals = ["Cat","Dog","Horse","Fish"]
vendors = ["Bertha's Kitty Boutique","K9 Supplies","Saddle & Tack Shoppe","Aquariums 'N' Stuff","Pet-R-Us"]
if(pet in Animals):
vendorIndex = Animals.index(pet)
else:
vendorIndex = 4
reqVendor = vendors[vendorIndex]
f= open(name+"_formLetter.txt","w+") #saving the file name with the <name>_formLetter.txt format
f.write(name+"\n")
f.write(street+"\n")
f.write(city+",")
f.write(state+"\n\n")
f.write("Dear Valued Customer:\n\n")
f.write("Happy Birthday! You are eligible for a "+str(discount)+"% discount at")
f.write(reqVendor+".\n\nHappy shopping,\n")
f.close()