[Tutor] Codeacademy Problem

Chris “Kwpolska” Warrick kwpolska at gmail.com
Mon Apr 29 17:20:08 CEST 2013


On Mon, Apr 29, 2013 at 5:15 PM, Joseph Parkton <jparkton at gmail.com> wrote:
> I am working on a codeacademy problem and I am stuck. The instructions are
> as follows:
>
> INSTRUCTIONS
>
> Below your existing code, write a function called trip_cost that takes two
> inputs, city and days. cityshould be the city that you are going to visit
> and days should be the number of days that you are staying.
>
> Have your function return the sum of the rental_car_cost, hotel_cost, and
> plane_ride_cost functions with their respective inputs.
>
>
> my code so far looks like this:
>
> def hotel_cost(nights):
>
>     nights = nights * 140
>
>     return nights
>
>
>
> def plane_ride_cost(city):
>
>     if city == 'Charlotte':
>
>         return 183
>
>     if city == 'Tampa':
>
>         return 220
>
>     if city == 'Pittsburgh':
>
>         return 222
>
>     if city == 'Los Angeles':
>
>         return 475
>
>
> def rental_car_cost(days):
>
>     dailyCost = 40
>
>     dailyCost = dailyCost * days
>
>     if days >= 3:
>
>         dailyCost = dailyCost - 20
>
>     if days >= 7:
>
>         dailyCost = dailyCost - 30
>
>     return dailyCost
>
>
>
> def trip_cost(city, days):
>
>     totalCost = plane_trip_cost(city) + hotel_cost(nights) +
> rental_car_cost(days)
>
>     #And here is where I am stuck...
>
>
> It is probably a simple answer but I don't know how to accomplish it. Any
> help is appreciated.
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>

Two options:
(a) replace `totalCost =` with `return`
-OR-
(b) add `return totalCost` under the equation.

You already used return before, so why didn’t you do it there?  Or was
this code auto-added by codecademy?
--
Kwpolska <http://kwpolska.tk> | GPG KEY: 5EAAEA16
stop html mail                | always bottom-post
http://asciiribbon.org        | http://caliburn.nl/topposting.html


More information about the Tutor mailing list