3

first post so go easy on me. I am trying to make it to where when I run my class the name of the restaurant comes back like a title. The problem I ran into was with joe's it comes back as Joe'S with a capital S when I use title(). When I use capitalize() Joe's comes back fine but burger king comes back as Burger king with a lower case k. I am trying to find out how to simplify this so I can have the capitalized letter of each word, without capitalizing the S after the apostrophe. The example I am working on is from Python Crash Course chapter 9. I am running Geany with python version 3.xx. Thanks for all the help.

class Restaurant():
    def __init__(self, restaurant_name, cuisine_type):
        """Initialize name and cuisine type"""
        self.restaurant_name = restaurant_name
        self.cuisine_type = cuisine_type

    def describe_restaurant(self):
        print(self.restaurant_name.title() + " serves " + self.cuisine_type)

    def open_restaurant(self):
        print(self.restaurant_name.capitalize() + " is now open!")

restaurant = Restaurant('joe\'s', 'mexican')
burger_king = Restaurant('burger king', 'burgers')
restaurant.describe_restaurant()
restaurant.open_restaurant()
burger_king.describe_restaurant()
burger_king.open_restaurant()
  • 1
    You can use [`string.capwords`](https://docs.python.org/3/library/string.html#string.capwords) – khelwood Jan 05 '17 at 11:54
  • Thanks for the help. Took some research with how to use this but I figured it out, I think. I did "from string import capwords". I didn't realize the string library was not included by default. then I wrapped capwords(self.restaurant_name) and it turned out perfect. Thank you. – joejunior253 Jan 06 '17 at 03:53

1 Answers1

0

Just split and join in open_restaurant

class Restaurant():
    def __init__(self, restaurant_name, cuisine_type):
        """Initialize name and cuisine type"""
        self.restaurant_name = restaurant_name
        self.cuisine_type = cuisine_type

    def describe_restaurant(self):
        print(self.restaurant_name.title() + " serves " + self.cuisine_type)

    def open_restaurant(self):
        Name = self.restaurant_name
        print(' '.join([x.capitalize() for x in Name.split(' ')]) + " is now open!")

restaurant = Restaurant('joe\'s', 'mexican')
burger_king = Restaurant('burger king', 'burgers')
restaurant.describe_restaurant()
restaurant.open_restaurant()
burger_king.describe_restaurant()
burger_king.open_restaurant()
Oxymoron88
  • 495
  • 3
  • 9