B
B
Banyanchik2020-04-18 22:46:21
Python
Banyanchik, 2020-04-18 22:46:21

Python error: what's the problem?

I can't figure out why it gives an error on the last line:

class Address:

    def __init__(self, street, city, state, zipcode):
        self.street = street
        self.city = city
        self.state = state
        self.zipcode = zipcode

    def get_street(self, street):
        return self.street

    def get_city(self, city):
        return self.city

    def get_state(self, state):
        return self.state

    def get_zipcode(self, zipcode):
        return self.zipcode

    def __str__(self):
        return str(self.street,self.city,self.state,self.zipcode)

address = Address('Grandview', 'Westland', 'Michigan', 48186)
street = address.get_street()
city = address.get_city()
state = address.get_state()
zipcode = address.get_zipcode()

print "%s, %s, %s, %s" % (street, city, state, zipcode)


Mistake:
TypeError
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-10-c76c12dc27b5> in <module>
     28 
     29 address = Address('Grandview', 'Westland', 'Michigan', 48186)
---> 30 street = address.get_street()
     31 city = address.get_city()
     32 state = address.get_state()

TypeError: get_street() missing 1 required positional argument: 'street'
get_street() missing 1 required positional argument: 'street'


Problem Statement:
Write a class representing a person's postal address. It should have separate fields for name, address (street, house number, apartment number), city, state, and postal code. The index must be numeric. Show an example of using the implemented class.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dmshar, 2020-04-18
@Banyanchik

get_street() - like get_city(), get_state(), by the way - require a mandatory parameter (as these functions are defined above). You do not set this parameter.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question