Ask your own question, for FREE!
Computer Science 16 Online
OpenStudy (anonymous):

what's wrong with this python code ? ] def rental_car_cost (days): car_cost == days *40 return car_cost if days >= 7: return car_cost - 50 elif days >= 3 and days <7: return car_cost - 20 else: return False def trip_cost (city, days): total ammount = rental_car_cost+ hotel_cost+ plane_ride_cost

OpenStudy (microbot):

what errors/exceptions do you get?

OpenStudy (microbot):

probably you never use the if statement because you have the return statement just before it. let me know if it is that

OpenStudy (espex):

I would concur with @MicroBot , the errors you are getting would be helpful and with your first return statement you are breaking out of your routine.

OpenStudy (anonymous):

thanks for the answer :)

OpenStudy (rsmith6559):

Your first, and probably most serious problem is: car_cost == days *40 == is a comparison operator. = is an assignment operator. Then you can get into your discounts not being applied. BTW, in the elif statement, you don't need to check if days >= 7. It was checked in the if part of that structure.

OpenStudy (microbot):

totaly missed that...agree with @rsmith6559 it is very important to understand the difference between a comparison operator (==) and an assignment operator (=). check this link :) http://www.tutorialspoint.com/python/python_basic_operators.htm

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!