Python Forum

Full Version: ValueError: invalid literal for int() with base 10: '0.5'
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, I'm having a problem with the code that I'm writing, this may be obvious as I'm new to Python, when I try to input a decimal whil writing my code I receive an error message, here is my code:

r = int(input("Enter the length of the row, in feet:"))
e = int(input("Enter the amount of space, in feet, used by an end-post assembly:"))
s = int(input("Enter the distance, in feet, between each vine:"))
v = ((r-2*e)/s)
print ("You have enough space for", v, "vines.")
This code works fine when I use numbers which are not decimals, however, I attempted to use a decimal while running it and this happened:

Enter the length of the row, in feet:100
Enter the amount of space, in feet, used by an end-post assembly:0.5
Traceback (most recent call last):
  File "C:\Users\Windows\AppData\Local\Programs\Python\Python38-32\Assignement 1.py", line 4, in <module>
    e = int(input("Enter the amount of space, in feet, used by an end-post assembly:"))
ValueError: invalid literal for int() with base 10: '0.5'
>>> 
I'm confused as the why I can't use a decimal, again this is probably obvious but I'm new to this, thank you.
A decimal value is not an integer, is it? Integers are whole numbers, Use float instead of int if you want a floating point value.
Yes, thank you Smile