ALL IN PYTHON LANGUAGE 1 Using the definition Restaurant n

*** ALL IN PYTHON LANGUAGE****

(1) Using the definition Restaurant = namedtuple(\'Restaurant\', \'name cuisine phone dish price\'), write the function Restaurant_change_price that takes two arguments, a Restaurant object and a number, and returns a Restaurant object with the same contents as the parameter except that the price has been increased by the specified number.

(2) Write a function called select_cheaper that takes a list of restaurants and a number (a float) and returns a list of all the restaurants whose price is less than the specified number.

(3) Write a function called average_price that takes a list of restaurants and returns the average price of (the best dishes at) those restaurants. (You may wish to write a separate function that takes a list of restaurants and returns the sum of the prices of (the best dishes at) those restaurants. But that\'s not required.)

(4) Write a print statement that calls one or more of the functions you defined above to print the average price of the Indian restaurants in the list RL.

(5) Write a print statement that calls one or more of the functions you defined above to print the average price at the Chinese and Thai restaurants (taken as one group) in the list RL.

(6) Write a print statement that calls one or more of the functions you defined above to print a list of the names of all the restaurants in RL with a price under $15.00.

(7) When we draw a rectangle in tkinter (and similarly for other figures), we have to specify the coordinates of its upper left and lower right corners. But sometimes it\'s more convenient to specify the center point of the rectangle and its height and width. Write a function create_rectangle_from_center that takes four arguments: the x-value and y-value of the point in the center of the rectangle and the height and width of the rectangle.

We don\'t know yet how to make create_rectangle_from_center() into a method that would let us say my_canvas.create_rectangle_from_center(), but you can call create_rectangle_from_center() without the my_canvas prefix: In the body of your function, you just call my_canvas.create_rectangle() with the appropriate arguments (based on the parameters of create_rectangle_from_center()). Note that the body of your function should only contain a call to create_rectangle; all the tkinter setup should be outside your function, in the main program.

Solution

print()
print()

# Restaurant attributes: name, kind of food served, phone number,
#   best dish, price of that dish

R1 = Restaurant(\"Taillevent\", \"French\", \"343-3434\", \"Escargots\", 24.50)
R2 = Restaurant(\"La Tour D\'Argent\", \"French\", \"343-3344\", \"Ris de Veau\", 48.50)
R3 = Restaurant(\"Pascal\", \"French\", \"333-4444\", \"Bouillabaisse\", 32.00)
R4 = Restaurant(\"Thai Touch\", \"Thai\", \"444-3333\", \"Mee Krob\", 10.95)
R5 = Restaurant(\"Thai Dishes\", \"Thai\", \"333-4433\", \"Paht Woon Sen\", 8.50)
R6 = Restaurant(\"Thai Spoon\", \"Thai\", \"334-3344\", \"Mussamun\", 9.00)
R7 = Restaurant(\"McDonald\'s\", \"Burgers\", \"333-4443\", \"Big Mac\", 3.95)
R8 = Restaurant(\"Burger King\", \"Burgers\", \"444-3344\", \"Whopper\", 3.75)
R9 = Restaurant(\"Wahoo\'s\", \"Fish Tacos\", \"443-4443\", \"Mahi Mahi Burrito\", 7.50)
R10 = Restaurant(\"In-N-Out Burger\", \"Burgers\", \"434-3344\", \"Cheeseburger\", 2.50)
R11 = Restaurant(\"The Shack\", \"Burgers\", \"333-3334\", \"Hot Link Burger\", 4.50)
R12 = Restaurant(\"Gina\'s\", \"Pizza\", \"334-4433\", \"Combo Pizza\", 12.95)
R13 = Restaurant(\"Peacock, Room\", \"Indian\", \"333-4443\", \"Rogan Josh\", 12.50)
R14 = Restaurant(\"Gaylord\", \"Indian\", \"333-3433\", \"Tandoori Chicken\", 13.50)
R15 = Restaurant(\"Mr. Chow\", \"Chinese\", \"222-3333\", \"Peking Duck\", 24.50)
R16 = Restaurant(\"Chez Panisse\", \"California\", \"222-3322\", \"Grilled Duck Breast\", 25.00)
R17 = Restaurant(\"Spago\", \"California\", \"333-2222\", \"Striped Bass\", 24.50)
R18 = Restaurant(\"Sriped Bass\", \"Seafood\", \"333-2233\", \"Cedar Plank Salmon\", 21.50)
R19 = Restaurant(\"Golden Pagoda\", \"Chinese\", \"232-3232\", \"Egg Foo Young\", 8.50)
R20 = Restaurant(\"Langer\'s\", \"Delicatessen\", \"333-2223\", \"Pastrami Sandwich\", 11.50)
R21 = Restaurant(\"Nobu\", \"Japanese\", \"335-4433\", \"Natto Temaki\", 5.50)
R22 = Restaurant(\"Nonna\", \"Italian\", \"355-4433\", \"Stracotto\", 25.50)
R23 = Restaurant(\"Jitlada\", \"Thai\", \"324-4433\", \"Paht Woon Sen\", 15.50)
R24 = Restaurant(\"Nola\", \"New Orleans\", \"336-4433\", \"Jambalaya\", 5.50)
R25 = Restaurant(\"Noma\", \"Modern Danish\", \"337-4433\", \"Birch Sap\", 35.50)
R26 = Restaurant(\"Addis Ababa\", \"Ethiopian\", \"337-4453\", \"Yesiga Tibs\", 10.50)


RL = [R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11, R12, R13, R14, R15, R16,
   R17, R18, R19, R20, R21, R22, R23, R24, R25, R26]

\"\"\"
from operator import attrgetter
def alphabetical(x:list) -> list:
    \'\'\'returns of list sorted by alphabetical order
    \'\'\'
    sorted(x, key = attrgetter(\"name\"))
    return sorted(x)
print(alphabetical(RL))
\"\"\"

def alphabetical_order(x:list) -> None:
    return x.name
def alphabetical(x:list) -> list:
    \'\'\'returns of list sorted by alphabetical order
    \'\'\'
    b = sorted(x, key = alphabetical_order)
    return b

print(alphabetical(RL))
  

print()

def alphabetical_names(x: list) -> list:
    \'\'\'takes a list x and returns a list of sorted names
    \'\'\'
    names = []
    for b in x:
        names.append(b.name)
    names.sort()
    return names
print(alphabetical_names(RL))

print()

def all_Thai(x: list) -> list:
    \'\'\'returns all thai restaurants in a list
    \'\'\'
    thai = []
    for b in x:
        if b.cuisine == \'Thai\':
            thai.append(b.name)
    return thai

print(all_Thai(RL))

print()

def select_cuisine(x: list, y: str) -> list:
    \'\'\'returns a list of restaurants whose cuisine matches the string y
    \'\'\'
    cuisine = []
    for b in x:
        if b.cuisine == y:
            cuisine.append(b)
    return cuisine
print(select_cuisine(RL, \'Burgers\'))

print()

def select_cheaper(x: list, y: float) -> list:
    \'\'\'returns a list of prices under price y
    \'\'\'
    cheap = []
    for b in x:
        if b.price < y:
            cheap.append(b)
    return cheap

print(select_cheaper(RL, 10.00))

print()

def average_price(x: list) -> float:
    \"\"\" Takes a list of restaurants and returns the avg price\"\"\"
    number = 0
    for b in x:
        number = b.price + number
    return number / 26

print(average_price(RL))

print()

print(average_price(select_cuisine(RL, \'Indian\')) * (26 / len(select_cuisine(RL, \'Indian\'))))
print()
print(average_price(select_cuisine(RL, \'Thai\') + select_cuisine(RL, \'Chinese\')) * (26/ (len(select_cuisine(RL, \'Thai\')) + len(select_cuisine(RL, \'Chinese\')))))
print()
print(alphabetical_names(select_cheaper(RL, 15)))
print()
print()
print(\' ---part(g)--- \')
print()
print()

import tkinter

my_window = tkinter.Tk()
my_canvas = tkinter.Canvas(my_window, width=700, height=700)
my_canvas.pack()
def create_rectangle_from_center(x: float, y:float, w:float, h:float) -> float:
    \'\'\'draws a rectangle based on the center point of the rectangle
    \'\'\'
    my_canvas.create_rectangle((x - (w/2)), y -(h/2), x + w/2, y + h/2)
    return
create_rectangle_from_center(400, 200, 200, 300

*** ALL IN PYTHON LANGUAGE**** (1) Using the definition Restaurant = namedtuple(\'Restaurant\', \'name cuisine phone dish price\'), write the function Restauran
*** ALL IN PYTHON LANGUAGE**** (1) Using the definition Restaurant = namedtuple(\'Restaurant\', \'name cuisine phone dish price\'), write the function Restauran
*** ALL IN PYTHON LANGUAGE**** (1) Using the definition Restaurant = namedtuple(\'Restaurant\', \'name cuisine phone dish price\'), write the function Restauran

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site