--- id: 6a0dcd03ee4e68698080ef66 title: "Challenge 302: Jet Lagged" challengeType: 29 dashedName: challenge-302 --- # --description-- Given a departure city, an arrival city, a flight duration in hours, and a direction of travel, return the number of jet lag hours the traveller is experiencing. The given cities will be from the following list that includes their UTC offset: | City | Offset | | - | - | | `"Los Angeles"` | -8 | | `"New York"` | -5 | | `"London"` | 0 | | `"Istanbul"` | +3 | | `"Dubai"` | +4 | | `"Hong Kong"` | +8 | | `"Tokyo"` | +9 | To calculate jet lag hours: 1. Find the timezone difference in hours between the two cities. 2. Determine the direction multiplier. If travelling `"east"`, it's 1.5, otherwise, it's 1.0. 3. Get the jet lag hours with the formula: timezone difference + (flight duration * 0.1) * direction multiplier Return the jet lag hours rounded to one decimal place. # --hints-- `get_jet_lag_hours("Istanbul", "Hong Kong", 10, "east")` should return `6.5`. ```js ({test: () => { runPython(` from unittest import TestCase TestCase().assertEqual(get_jet_lag_hours("Istanbul", "Hong Kong", 10, "east"), 6.5)`) }}) ``` `get_jet_lag_hours("London", "New York", 8, "west")` should return `5.8`. ```js ({test: () => { runPython(` from unittest import TestCase TestCase().assertEqual(get_jet_lag_hours("London", "New York", 8, "west"), 5.8)`) }}) ``` `get_jet_lag_hours("Hong Kong", "Tokyo", 4, "east")` should return `1.6`. ```js ({test: () => { runPython(` from unittest import TestCase TestCase().assertEqual(get_jet_lag_hours("Hong Kong", "Tokyo", 4, "east"), 1.6)`) }}) ``` `get_jet_lag_hours("Dubai", "London", 7, "west")` should return `4.7`. ```js ({test: () => { runPython(` from unittest import TestCase TestCase().assertEqual(get_jet_lag_hours("Dubai", "London", 7, "west"), 4.7)`) }}) ``` `get_jet_lag_hours("Los Angeles", "Hong Kong", 15, "west")` should return `17.5`. ```js ({test: () => { runPython(` from unittest import TestCase TestCase().assertEqual(get_jet_lag_hours("Los Angeles", "Hong Kong", 15, "west"), 17.5)`) }}) ``` `get_jet_lag_hours("Tokyo", "Dubai", 9, "west")` should return `5.9`. ```js ({test: () => { runPython(` from unittest import TestCase TestCase().assertEqual(get_jet_lag_hours("Tokyo", "Dubai", 9, "west"), 5.9)`) }}) ``` `get_jet_lag_hours("New York", "Istanbul", 10, "east")` should return `9.5`. ```js ({test: () => { runPython(` from unittest import TestCase TestCase().assertEqual(get_jet_lag_hours("New York", "Istanbul", 10, "east"), 9.5)`) }}) ``` # --seed-- ## --seed-contents-- ```py def get_jet_lag_hours(departure_city, arrival_city, flight_duration, direction): return departure_city ``` # --solutions-- ```py def get_jet_lag_hours(departure_city, arrival_city, flight_duration, direction): offsets = { "Los Angeles": -8, "New York": -5, "London": 0, "Istanbul": 3, "Dubai": 4, "Hong Kong": 8, "Tokyo": 9 } timezone_diff = abs(offsets[arrival_city] - offsets[departure_city]) multiplier = 1.5 if direction == "east" else 1.0 score = timezone_diff + (flight_duration * 0.1) * multiplier return round(score, 1) ```