Skip to main content
Stack Overflow
  1. About
  2. For Teams

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

How to spot my error in Python?

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())

Answer*

Draft saved
Draft discarded
Cancel
1
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center. Commented Feb 14, 2022 at 17:43

lang-py

AltStyle によって変換されたページ (->オリジナル) /