Question regarding input


#1

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
hotel_cost(nights)


#2

string multiplication:

30 * "h"

will give h 30 times.

To do math, both values need to be integers


#3

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


#4

Did you solve it? Do you need more help?


#5

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


#6

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

do not use eval()


#7

Ok i solved it, thanks !


#8

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