python - Can't get raw_input to return a number -


print "how old you?", age = raw_input() print "how tall in inches?", height = raw_input() print "how weigh in pounds", weight = raw_input()  print "so, %r years old, %r inches tall, , %d kilograms." % ( age, height, weight / 2.2)  

so new code , code. when use terminal compile it, this:

how old you? 1 how tall in inches? 1 how weigh in pounds 1 traceback (most recent call last):   file "ex11.py", line 9, in <module>    age, height, weight / 2.2)  typeerror: unsupported operand type(s) /: 'str' , 'float' 

can please explain me did wrong?

raw_input returns string object. need explicitly convert number object if plan use such (perform mathematical operations on it):

weight = int(raw_input())  #or  weight = float(raw_input()) 

use int if number integer. otherwise, use float if input can have decimal part such 10.1.


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -