Guest User

Untitled

a guest
Oct 12th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. #Create restaurant class with restaurant object and describe_restaurant function
  2.  
  3. class restaurant:
  4. def __init__(self, n, restaurant_name, cuisine_type):
  5. self.n = n
  6. self.restaurant_name = restaurant_name
  7. self.cuisine_type = cuisine_type
  8.  
  9. def describe_restaurant(self):
  10. print("{} serves {}".format(restaurant.restaurant_name, restaurant.cuisine_type))
  11.  
  12. #localplaces will contain the restaurant objects
  13.  
  14. localplaces = []
  15. n = len(localplaces)
  16. active = True
  17.  
  18. while active:
  19. localplaces.append(restaurant(n, input("Restaurant Name: "), input("Cuisine type: ")))
  20. repeat = input("Do you want to add another item?: ")
  21. if repeat.strip().lower() in ["n", "no"]:
  22. active = False
  23. else:
  24. while repeat.strip().lower() not in ['y', 'yes', 'n', 'no']:
  25. repeat = input("Add another item? [y/n]: ")
  26.  
  27. #loop through localplaces printing the object info as defined by the
  28.  
  29. for restaurant in localplaces:
  30. print("n" + restaurant.describe_restaurant().format)
  31.  
  32. Restaurant Name: bobs
  33. Cuisine type: burgers
  34. Do you want to add another item?: n
  35. bobs serves burgers
  36. Traceback (most recent call last):
  37. File "C:/Users/nicholl/PycharmProjects/untitled/Coordinates.py", line 24, in <module>
  38. print("n" + restaurant.describe_restaurant().format)
  39. AttributeError: 'NoneType' object has no attribute 'format'
  40.  
  41. Restaurant Name: bobs
  42. Cuisine type: burgers
  43. Do you want to add another item?: n
  44. bobs serves burgers
  45. Traceback (most recent call last):
  46. File "C:/Users/user/PycharmProjects/Test/Test11111c.py", line 24, in <module>
  47. print("n" + restaurant.describe_restaurant())
  48. TypeError: can only concatenate str (not "NoneType") to str
Add Comment
Please, Sign In to add comment