I have just recently started to code at my school and I am learning how to use Python. Our teacher gave us this task:
- Create a class and give it the name “CustomerInfo”.
- Create a constructor with no parameters ( only self ).
- Create user inputs for name, order, quantity, and address.
- Create mutator methods for name, order, quantity, and address.
- Create accessor methods for name, order, quantity, and address.
- Create a new CustomerInfo() object and call it “customer1”.
- Print out the customer information.
Here are my codes:
class CustomerInfo:
def __init__ ():
self.name = theName
self.order = theOrder
self.quantity = theQuantity
self.address = theAddress
def setName( self, newName ):
self.Name = newName
def setOrder ( self, newModel ):
self.model = newModel
def setQuantity ( self, newQuantity ):
self.quantity = newQuantity
def setAddress (self, newAddress ):
self.address = newAddress
def getName ( self ):
return self.name
def getOrder ( self ):
return self.order
def getQuantity ( self ):
return self.quantity
def getAddress ( self ):
return self.address
name = input("Enter your name: ")
order = input("Enter your order: ")
quantity = int(input("Enter your quanity: "))
address = input("Enter your address: "))
customer1 = CustomerInfo()
print ( "Name: ", customer1.name)
print ( "Order: ", customer1.order)
print ( "Quanity: ", customer1.quantity)
print ( "Address: ", customer1.address)
However, I got the following Error:
TypeError: __init__() takes 0 positional arguments but 1 was given
I added (self)
to __init__
as described in the comments, and now when I run the module the inputs work but after I put the inputs of name, order, quantity, and address, the outcome came out like this:
Traceback (most recent call last):
File line 32, in <module>
customer1 = CustomerInfo()
File line 4, in __init__
self.name = theName
NameError: name 'theName' is not defined