Hallo zusammen,
ich beschäftige mich seit Kurzem mit der Programmierung in Python und versuche momentan diverse Mini-Aufgaben zu lösen.
Folgende Problemstellung, bei der ein einfacher Urlaubskostenrechner erstellt werden soll, lässt mich z.Z. verzweifeln. Ich bekomme immer folgenden Fehler angezeigt: Oops, try again. trip_cost('Los Angeles', 7) raised an error: global name 'ental_car_cost' is not defined.
Hier die Aufgabe (englische Beschreibung)
Beispiel zur Aufgabe:
We define two simple functions, double
and triple(p) that return 2 times or 3 times their input. Notice that they have n and p as their arguments.
We define a third function, add(a, b) that returns the sum of the previous two functions when called with a and b, respectively.
Meine Aufgabe:
Below your existing code, define a function called trip_cost that takes two arguments, city and days.
Like the example above, have your function return the sum of calling the rental_car_cost(days), hotel_cost(days), and plane_ride_cost(city) functions.
It is completely valid to call the hotel_cost(nights) function with the variable days. Just like the example above where we call double
with the variable a, we pass the value of days to the new function in the argument nights.
Meine bisherige Lösung:
ich beschäftige mich seit Kurzem mit der Programmierung in Python und versuche momentan diverse Mini-Aufgaben zu lösen.
Folgende Problemstellung, bei der ein einfacher Urlaubskostenrechner erstellt werden soll, lässt mich z.Z. verzweifeln. Ich bekomme immer folgenden Fehler angezeigt: Oops, try again. trip_cost('Los Angeles', 7) raised an error: global name 'ental_car_cost' is not defined.
Hier die Aufgabe (englische Beschreibung)
Beispiel zur Aufgabe:
We define two simple functions, double

We define a third function, add(a, b) that returns the sum of the previous two functions when called with a and b, respectively.
Code:
def double(n):
return 2 * n
def triple(p):
return 3 * p
def add(a, b):
return double(a) + triple(b)
Below your existing code, define a function called trip_cost that takes two arguments, city and days.
Like the example above, have your function return the sum of calling the rental_car_cost(days), hotel_cost(days), and plane_ride_cost(city) functions.
It is completely valid to call the hotel_cost(nights) function with the variable days. Just like the example above where we call double

Meine bisherige Lösung:
Code:
def hotel_cost(nights):
return 140 * nights
def plane_ride_cost(city):
if city == "Charlotte":
return 183
elif city == "Tampa":
return 220
elif city == "Pittsburgh":
return 222
elif city == "Los Angeles":
return 475
else:
return "Please choose your city!"
def rental_car_cost(days):
rental_car_cost = 40 * days
if days >= 7:
rental_car_cost = (40 * days) - 50
elif days >= 3:
rental_car_cost = (40 * days) - 20
return rental_car_cost
[B]def trip_cost(city, days):
return hotel_cost(days) + plane_ride_cost(city) + ental_car_cost(days)[/B]
# nights == days!
Zuletzt bearbeitet von einem Moderator: