Answered step by step
Verified Expert Solution
Question
1 Approved Answer
import csv from datetime import date, datetime class Customer: def _ _ init _ _ ( self , id , name, email, phone _ number,
import csv
from datetime import date, datetime
class Customer:
def initself id name, email, phonenumber, dateofbirth, address:
self.id id
self.name name
self.email email
self.phonenumber phonenumber
self.dateofbirth dateofbirth
self.address address
def reprself:
return fCustomeridselfid nameselfname emailselfemail phonenumberselfphonenumber dateofbirthselfdateofbirth addressselfaddress
def calculateageself dateofbirth:
today date.today
birthdate datetime.strptimedateofbirth, Ymd
age today.year birthdate.year todaymonth, today.daybirthdate.month, birthdate.day
return age
def getidself:
return self.id
def getnameself:
return self.name
def getemailself:
return self.email
def getphonenumberself:
return self.phonenumber
def getaddressself:
return self.address
def setnameself newname:
self.name newname
def setemailself newemail:
self.email newemail
def setphonenumberself newphonenumber:
self.phonenumber newphonenumber
def setaddressself newaddress:
self.address newaddress
class CustomerManager:
def initself:
self.customers
def addcustomerself customer:
self.customers.appendcustomer
def removecustomerself customer:
self.customers.removecustomer
def getcustomersbyagerangeself minage, maxage:
today date.today
customersinrange
for customer in self.customers:
birthdate datetime.strptimecustomerdateofbirth, Ymd
age today.year birthdate.year todaymonth, today.daybirthdate.month, birthdate.day
if minage age maxage:
customersinrange.appendcustomer
return customersinrange
def getcustomersbyaddressself address:
customerswithaddress
for customer in self.customers:
if customer.address address:
customerswithaddress.appendcustomer
return customerswithaddress
def exportdataself filename:
try:
with openfilename modew newline as file:
writer csvwriterfile
writer.writerowID 'Name', 'Email', 'Phone Number', 'Date of Birth', 'Address'
for customer in self.customers:
writer.writerowcustomerid customer.name, customer.email, customer.phonenumber, customer.dateofbirth, customer.address
except IOError as e:
printfAn error occurred while exporting data: e
# Function to get user input for creating a new customer
def createcustomer:
customerid intinputEnter customer ID:
customername inputEnter customer name:
customeremail inputEnter customer email:
customerphonenumber inputEnter customer phone number:
customerdateofbirth inputEnter customer date of birth YYYYMMDD:
customeraddress inputEnter customer address:
return Customercustomerid customername, customeremail, customerphonenumber, customerdateofbirth, customeraddress
# Example usage
customermanager CustomerManager
while True:
choice inputEnter a to add a new customer, q to quit:
if choice.lowera:
newcustomer createcustomer
customermanager.addcustomernewcustomer
printCustomer added successfully."
elif choice.lowerq:
break
else:
printInvalid input. Please try again."
# Export customer data to a CSV file
customermanager.exportdatacustomerscsv get user input
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started