4/7 transportation


Hi Wizmarco
what does $ in python mean? I tried googling it but could not find any answers there.

Thanks in advance

4/7 Transportation

i don't see a $ somewhere in the topic, why you ask?


in my earlier code for the exercise of 4/7 transportation for the calculation of rental_car_cost(days), i made the same mistake of including the $ sign. it is only after i removed the $ sign, does it work. i saw that Wizmarco answered a similar thread advising the removal of $ sign and would like to ask to find out why it didn't work

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

def rental_car_cost(days):
    rental_car_cost = $40 * days
    if days >=7:
        rental_car_cost -= $50
    elif days >=3:
        rental_car_cost -= $20
    return rental_car_cost


$ is nothing in python, so it will throw an error. By removing it, 40 becomes an integer

we could use "$" to show the user the amount is in dollar, but we don't use it in the math


I see. thanks so much :slight_smile:


If you really want to have the $ sign there, you could just do:

print ("$",variable)

this may not apply in the specified problem, but just if your about to print a value in another code.


Very useful point of reference after several minutes of banging my head against the wall.

My only question is: why wouldn't the second discount be written as elif days >=3 and days < 7 ?

3 or more days works for the purposes of the exercise, but wouldn't it (potentially) make you eligible for the $50 discount? Ex: 8 > 3, which satisfies the requirements for the $50 discount (days >= 7), as well as for the $20 discount (days >= 3).

Just curious...


If the initial if days >= 7: fails, then the elif statement will proceed. Neither one can happen at the same time.


once the if condition is evaluate to true, the elif and else will never run

So there is no need to verify that the car is rented for less then 7 days in your elif condition, if takes cares of that


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.