Ana sayfa
/
Teknoloji
/
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

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

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.6274 Voting
avatar
Volkan
Usta · 5 yıl öğretmeni
Uzman doğrulaması

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:<br />```python<br />def Destinations(destinations, prices, budget):<br /> affordable_destinations = [dest for dest, price in zip(destinations, prices) if price <= budget]<br /> return affordable_destinations<br />```<br />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:<br />```python<br />destinations = ['Paris', 'London', 'Berlin', 'Tokyo']<br />prices = [100, 150, 80, 200]<br />budget = 400<br /><br />affordable_destinations = Destinations(destinations, prices, budget)<br />print(' '.join(affordable_destinations))<br />```<br />This will output the following:<br />```<br />London Berlin<br />```
Derecelendirmek için tıklayın: