Laura is looking for a restaurant to eat dinner with her parents. Write a function that takes in a list of tuples in the format [(restaurant name, tables left, total tables),...]
Determine which restaurant is best for Laura to go. A restaurant is considered best if it’s a at greater than 50% total tables left.
Return a list of all the best restaurants.
Here is the complete code with comments to help understand the code
def func(inputtuples):
# First make an empty list which we will fill and return at last
returnlist = []
# Now iterate through the list of tuples
for x in inputtuples:
# if free seats is more than half of total seats then append that tuple to the returnlist
if x[1]/x[2] > 0.5:
returnlist.append(x[0])
return returnlist
# Here is a list of tuple for putting in the function
listoftuples = [("Taj Hotel", 100, 150), ("Mira Hotel", 50, 200), ("Hotel California", 100, 120),
("Family Restaurant", 500, 700), ("Homely Restaurant", 300, 500), ("Punjabi Restaurant", 300, 900), ]
# calling the funtion and storing the result in anslist
anslist = func(listoftuples)
# printing the ans list
print(str(anslist))
Here is the code image to help understand the indentation
Here is the output for the above code
NOTE: If you like the answer a thumbs up would be highly appreciated. Have a good day :)
After the update here is the new output
Get Answers For Free
Most questions answered within 1 hours.