Question regarding input


I have some questions regarding the raw_input
this is the function i created. It asks an input from the user. I tested it by using some numbers. For example i input “1” but instead from getting 140, i got tons of copies of 1. Can i know what’s the problem?

nights = raw_input(“how many nights :”)
def hotel_cost(nights):
total = 140 * nights
print total
return 140 * nights


string multiplication:

30 * "h"

will give h 30 times.

To do math, both values need to be integers


Oh i see. So that’s the reason i got so many 1. Thanks a lot for your reply !!


Did you solve it? Do you need more help?


How do i change the string to int? Do i use “int()” in the function argument or ?


you can use int(), that is fine, that can convert a string to integer

do not use eval()


Ok i solved it, thanks !


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