print "Welcome to my converter!"
#inches to centimeters
def in_inches(n):
return(n * 2.54)
#pounds to kilograms
def in_pounds(n):
return(n * 0.453592)
while True:
print "Which conversion?"
print "1 is for in to cm"
print "2 is for lbs to kg"
choice = raw_input("?")
if choice == "1":
n = raw_input("How many inches?")
res = in_inches(n)
print "In %s in we have %s cm." % (n, res)
elif choice == "2":
n = raw_input("How many pounds?")
res = in_pounds(n)
print str(n) + " is " + str(res) + " Kilograms"
else:
print "Invalid choice"
I have this code but it fails to work when I introduce it to the console. The console says:
Traceback (most recent call last):
File "converter.py", line 20, in <module>
res = in_inches(n)
File "converter.py", line 4, in in_inches
return(n * 2.54)
TypeError: can't multiply sequence by non-int of type 'float'
What does this mean and how could I fix it? Thanks in advance. `