Transportation


#1
def rental_car_cost(days):
    cost = 40 * days
    if days >= 7:
        cost -= 50
    elif days >= 3 or days < 7:
        cost -= 20
    else:
        return cost

it's not formatting my indentation, but i believe all of that is correct. i'm not getting any indentation errors. my error is "Oops, try again. It looks like rental_car_cost returns 20 instead of the correct amount (40) for 1 days."

i'm not sure where i've gone wrong.

edit: i changed "days <=7" to "days <7" because if i can't have both discounts, the cost can't =7 on both counts. i also added an "else:" argument at the end, followed by "return cost." i'm getting the same error as above except the amount is now "None" instead of "20."

edit #2: got the formatting correct.

edit #3: FINALLY. had to get creative and do some googling. i used the "in range" operator to lock that statement between 3 and 7. i'm not sure that ">=3 or <7" was getting it done. the below code finally works.

def rental_car_cost(days):
    cost = 40 * days
    if days >= 7:
        return cost - 50
    elif days in range(3, 7):
        return cost - 20
    else:
        return cost
print rental_car_cost(1)

#2

Mine worked fine with the
elif days >= 3:
statement.

or days < 7: statement may not be necessary.
Try with different days when you print.


#3

Also, else: statement is not needed here.
Simply use return cost.
You could also try "and" statment instead of "or"


#4

thank you. i'll try without the else: but i read in another thread that, essentially, days 0, 1, and 2 are not accounted for.

and i initially tried "and" but it returned an error. however, i may have had some other error i wasn't aware of. i'll give it a try.

i'm still thinking something else more simple is wrong somewhere. the error i'm getting doesn't seem to point to either of those things. but as i said, i'll give it a try and see.

thank you for the feedback!


#5

I meant check with different parameters when you print.


#6

so i'm not actually printing anything. it wasn't listed in the steps or shown in the example, but could that be what i'm missing? i'm only using "return cost."


#7

finally got it figured out. made an edit to my post. thank you, again, for your comments!


#8

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