Planning Your Trip


Hello everybody,

I need a little help from you guys.
Am playing with this exercise, trying to understand it better and i have come across an "error".

In the exercise Planning Your Trip, the task is to - Define a function called hotel_cost with one argument nights as input.The hotel costs $140 per night. So, the function hotel_cost should return 140 * nights.-

I have done that, but i wanted to make it so as to give it my input, and it looks like this.

nights = raw_input("How many nights are you staying?")

def hotel_cost (nights):
    print 140 * nights
    return 140 * nights

The answer i received when i, for example typed in 2, is 2 printed 140 times. How can i code it to give me value of 280?

Thanks in advance!



raw_input doesn't store the number as a integer, which means you get this:

print 140 * '2'

2 needs to be a integer:

nights = int(raw_input("How many nights are you staying?"))


Thank you for your assistance.

Have a good day.


140 * a string will print the string 140 times as you discovered :stuck_out_tongue:


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