'I need to covernt 5'11" to CM with python code
I am working on a homework assignment that I need to take the heightfield in an attribute table and have it be converted to CM in another field. Right now I have:
with arcpy.da.SearchCursor(position + ".shp", "height") as cursor:
for row in cursor: heightcm = row[0]
height = heightcm.split("' ")
feet = int(height[0])
inches = int(height[1])
cm = (12*feet + inches)* 2.54
print(cm)
I know the format of 5'11" is messing up my split, but I am unsure how to fix this. Could anyone please help me.
I am getting a ValueError: invalid literal for int() with base 10: ' 1"'
Solution 1:[1]
To convert you could do this
for row in cursor:
heightcm = row[0]
height = heightcm.split("'")
feet = int(height[0])
inches = int(height[1][:-2])
cm = (12*feet + inches)* 2.54
print(cm)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
