Anasayfa
/
Teknoloji
/
Part 1 (30pts): Write a Python Function :Destinations() That Takes Two Lists and an Integer as Parameters: a List of Destinations

Soru

Part 1 (30pts): Write a Python function :Destinations() that takes two lists and an integer as parameters: a list of destinations (strings), a list of corresponding flight prices (integers), a budget value (integer). The function shall return a list of destinations that are within the specified budget (s). Assumption: Both lists are of the same length and each price corresponds to the destination at the same index. Write Python statements that create two lists (destinations and prices), input a budget value, call th function to get list of affordable-destinations and print the affordable destinations with space betwee them, as seen in the sample run below. You can use the following lists or create your own: destinations=['Paris', ' Lon Berlin', "Tokyo'l Plea se enter maximum budget: 400 Avali ts: London Berlin

Çözüm

4.6 (274 Oylar)
Volkan
Uzman doğrulaması
Usta · 5 yıl öğretmeni

Cevap

Here is the Python function `Destinations()` that takes two lists and an integer as parameters and returns a list of destinations that are within the specified budget:```pythondef Destinations(destinations, prices, budget): affordable_destinations = [dest for dest, price in zip(destinations, prices) if price <= budget] return affordable_destinations```To create two lists (destinations and prices), input a budget value, call the function to get the list of affordable destinations, and print the affordable destinations with space between them, you can use the following Python statements:```pythondestinations = ['Paris', 'London', 'Berlin', 'Tokyo']prices = [100, 150, 80, 200]budget = 400affordable_destinations = Destinations(destinations, prices, budget)print(' '.join(affordable_destinations))```This will output the following:```London Berlin```