Issue
Here is the example of the problem i am having it gives a duplicate of what i have entered for raw_input how do i access the value of raw_input and use it as a parameter of the function any one can help? i tried many times to amend it but didn't see any light of it i kind of know that the code must have treated the value as string but because i am new to python i don't have the necessary knowledge to solve it and it would be appreciated to have a full detailed how to. Inculcate me :)
def hotel_cost(nights):
return nights*140
a=raw_input("please enter number")
print hotel_cost(a)
thank you to all that contribute :)
Solution
raw_input
returns a string, you should convert it to an integer using int()
:
a = int(raw_input("please enter number: "))
Example:
>>> "12"*10 # This is what your code is doing
'12121212121212121212'
>>> int("12")*10 # Expected output
120
Answered By - Ashwini Chaudhary
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.