Python Forum
Can’t get program to run properly
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can’t get program to run properly
#1
#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()
Reply


Messages In This Thread
Can’t get program to run properly - by ITnet20 - Dec-03-2019, 05:42 AM
RE: Can’t get program to run properly - by buran - Dec-04-2019, 07:10 PM
File issues - by ITnet20 - Dec-04-2019, 05:58 AM
RE: File issues - by buran - Dec-04-2019, 09:45 AM
RE: File issues - by jefsummers - Dec-04-2019, 03:16 PM
RE: File issues - by ITnet20 - Dec-04-2019, 06:16 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  The program isn't counting the total properly DanielCook 1 1,751 Jul-09-2020, 04:51 PM
Last Post: mrdominikku

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020