height_feet = int(input("Enter portion of height in feet "))
height_inch = int(input("Enter portion of heigh in inches"))
height_in_inch = height_feet * 12 + height_inch
height_in_cm = height_in_inch * 2.54
print (height_in_cm)
Enter portion of height in feet 6
Enter portion of heigh in inches1.5
Traceback (most recent call last):
File "Untitled.py", line 2, in <module>
height_inch = int(input("Enter portion of heigh in inches"))
ValueError: invalid literal for int() with base 10: '1.5'
>>>
I'm brand new to python and I don't understand why it displays this error when I try to multiply by something with a decimal
这应该是float
类型,而不是int
类型。
In Python and elsewhere, ints are only whole numbers. 1.5, 1.2, pi, anything with a decimal is not an int. You want float
to describe them. It's short for floating point number.
change to : int(float(input("Enter portion of heigh in inches")))
str
to float
to int
should work if str
is something like 1.333
str
to int only works when str
is an integer like 4
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.