Python3. OOP Dusty Phillips

I'm reading a book named Python 3 OOP by Dusty Phillips, and when I try to run the following code:

class Property:

    def __init__(self, square_feet='', beds='', baths='', **kwargs):
        super().__init__(**kwargs)
        self.square_feet = square_feet
        self.num_bedrooms = beds
        self.num_baths = baths

    def display(self):
        print("PROPERTY DETAILS")
        print("================")
        print("square footage: {}".format(self.square_feet))
        print("bedrooms: {}".format(self.num_bedrooms))
        print("bathrooms: {}".format(self.num_baths))
        print()

    def prompt_init():
        return dict(square_feet=input("Enter the square feet: "),
                    beds=input("Enter number of bedrooms: "),
                    baths=input("Enter number of baths: "))

    prompt_init = staticmethod(prompt_init)

class Apartment(Property):

    valid_laundries = ("coin", "ensuite", "none")
    valid_balconies = ("yes", "no", "solarium")

    def __init__(self, balcony='', laundry='', **kwargs):
        super().__init__(**kwargs)
        self.balcony = balcony
        self.laundry = laundry

    def display(self):
        super().display()
        print("APARTMENT DETAILS")
        print("================")
        print("laundry: {}".format(self.laundry))
        print("has balcony: {}".format(self.balcony))

        parent_init = Property.prompt_init()

        laundry = ''
        while laundry.lower() not in Apartment.valid_laundries:
            laundry = input(
            "What laundry facilities does the property have? "
            "({})".format(", ".join(Apartment.valid_laundries))

        balcony = ''
        while balcony.lower() not in Apartment.valid_balconies:
            balcony = input(
            "Does the property have a balcony? "
            "({})".format(", ".join(Apartment.valid_balconies))

        parent_init.update({"laundry": laundry, "balcony": balcony})

        return parent_init

    prompt_init = staticmethod(prompt_init)

I always get the same error in line 49:

    balcony = ''
          ^
SyntaxError: invalid syntax

What am I missing?

Answers


You are missing a closing ) on the preceding line:

laundry = input(
"What laundry facilities does the property have? "
"({})".format(", ".join(Apartment.valid_laundries))
#                                                ^^?

You opened 3 parentheses (for input(), str.format() and str.join()) but closed only 2.

You make the same mistake a few lines further on:

balcony = input(
"Does the property have a balcony? "
"({})".format(", ".join(Apartment.valid_balconies))

while laundry.lower() not in Apartment.valid_laundries:
            laundry = input(
            "What laundry facilities does the property have? "
            "({})".format(", ".join(Apartment.valid_laundries))

        balcony = ''

There is a ) missing just before balcony definition (line 47).


You didn't close the parenthesis for input... twice. You need a closed parenthesis both at the end of line 111 and of line 117.


Count your parentheses:

while laundry.lower() not in Apartment.valid_laundries:
    laundry = input(
    "What laundry facilities does the property have? "
    "({})".format(", ".join(Apartment.valid_laundries))

Syntax errors usually mean that there's a problem just before the error. In this case the problem is that you've opened a parenthesis without closing it.


Need Your Help

Does Angular Dart support ng-repeat-start and ng-repeat-end?

dart angular-dart

AngularJS supports a ng-repeat-start and ng-repeat-end directive to have the ng-repeat repeat with several elements that are siblings. Is there a similar feature in Angular Dart or a different meth...

Java Application Installers

java installer toolkit

I'm not looking for java-web-start, I'm looking for a thick-client application installation toolkit. I've got a stand-alone application that consists of several files (jar files, data files, etc) ...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.