buonasera ragazzi,
ho scritto un pezzo di codice seguendo la guida codeacademy, sicuramente interpreto male il testo, ma non riesco a capire (è mezzoretta che guardo per capire) come mai ho questo errore:
Oops, try again. hotel_cost(1) raised an error: maximum recursion depth exceeded
il codice è questo
codice:
def hotel_cost(nights):
nights = 1 * 140
return hotel_cost(nights)
def plane_ride_cost(city):
if city == "bergamo":
return 100
elif city == "milano":
return 140
elif city == "brescia":
return 105
return plane_ride_cost(city)
def rental_car_cost(days):
cost = 40 * days
if days >= 7:
cost -= 50
elif days >= 3:
cost -= 20
return cost
def trip_cost(city, days):
return rental_car_cost(days) + hotel_cost(days) + plane_ride_cost(city)
la consegna dell'esercizio invece è questa
- 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(n) with the variable a, we pass the value of days to the new function in the argument nights.
per eventuali chiarezze il codice ci esempio a cui riferisce il testo dell'esercizio è questo
codice:
def double(n):
return 2 * n
def triple(p):
return 3 * p
def add(a, b):
return double(a) + triple(b)