Write a class named Person with data attributes for a person’s name, address, and telephone number. Next, write a class named Customer that is a subclass of the Person class.
The Customer class should have a data attribute for a customer number and a Boolean data attribute indicating whether the customer wishes to be on a mailing list. Demonstrate an instance of the Customer class in a simple program.'
This is what I have for my code, but I keep getting the following error:
Traceback (most recent call last):
File "/Users/ryanraben/Desktop/person1.py", line 45, in <module>
import customer
ModuleNotFoundError: No module named 'customer'
I have been struggling with this class this semester. I found someone asking a similar question here in Stack Overflow but their code was very different than what I had (and if I copied their code I still could not get the correct results). This was a video module and I entered my code as it appeared on the instructor's screen, but obviously I didn't do it right because his code works and mine does not.
class Person:
def __init__(self, name, address, phone):
self.__name = name
self.__address = address
self.__phone = phone
def set_name (self, name):
self.__name = name
def set_address (self, address):
self.__address = address
def set_phone (self, phone):
self.__phone = phone
def get_name (self):
return self.__name
def get_address (self):
return self.__address
def get_phone (self):
return self.__phone
class Customer (Person):
def __init__(self, name, address, phone, customer_number, mailing_list):
Person.__init__(self, name, adress, phone)
self.__customer_number = customer_number
self.__mailing_list = mailing_list
def set_customer_number (self, customer_number):
self.__customer_number = customer_number
def set_mailing_list(self, mailing_list):
self.__mailing_list = mailing_list
def get_customer_number(self):
return self.__customer_number
def get_mailing_list (self):
return self.__mailing_list
import customer
name = input ('Name: ')
address = input ('Address: ')
phone = input ('Phone: ')
customer_number = input ('Customer number: ')
mail = input ('Include in mailing list? (y/n): ')
if mail.lower()=='y':
mailing_list = True
else:
mailing_list = False
my_customer = customer.Customer (name, address, phone, customer_number, mailing_list)
print ('Customer Information')
print ('-----------------------------')
print ('Name: ', my_customer.get_name())
print ('Address: ', my_customer.get_address())
print ('Phone: ', my_customer.get_phone())
print ('Customer number: ', my_customer.get_customer_number())
print ('Mailing list: ', my_customer.get_mailing_list())
-
I'm sorry. This programming stuff is all Greek to me. I thought it was the easiest way to explain what I was doing. My apologies, and thank you for the help below.Ryan L Raben– Ryan L Raben2017年04月15日 22:47:21 +00:00Commented Apr 15, 2017 at 22:47
-
1No worries, we were all new once, I'm glad to help! Welcome to the communityScottishTapWater– ScottishTapWater2017年04月16日 01:40:31 +00:00Commented Apr 16, 2017 at 1:40
2 Answers 2
This is a pretty common error:
You're attempting to import the library of customer and your IDE is simply not able to find this file.
Since you're defining the Class Customer I can't see any reason why you would need to import this non-existant library.
Consequently, I suggest you delete the line import customer.
That is unless I've misunderstood something.
Comments
remove this line(import customer) and remove customer from 'customer.Customer' while creating the object. After all of this you have error of 'adress' not defined. Find this attribute in your code and change it to address. Thats All dear.