Python Forum
ValueError: invalid literal for int() with base 10: '0.5'
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ValueError: invalid literal for int() with base 10: '0.5'
#1
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.
Reply
#2
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.
Reply
#3
Yes, thank you Smile
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  ValueError: invalid literal for int() with base 10: omega_elite 5 5,679 Dec-30-2020, 06:11 AM
Last Post: delonbest
  invalid literal for int() with base 10: '# NRECS: 1096\n' Baloch 8 4,459 May-24-2020, 02:08 AM
Last Post: Larz60+
  invalid literal for int() with base 10: '' mrsenorchuck 5 5,332 Apr-29-2020, 05:48 AM
Last Post: markfilan
  ValueError: invalid literal for int() with base 10: '\n' srisrinu 9 5,583 Apr-13-2020, 01:30 PM
Last Post: ibreeden
  zlib decompress error: invalid code lengths set / invalid block type DreamingInsanity 0 6,744 Mar-29-2020, 12:44 PM
Last Post: DreamingInsanity
  input-ValueError: invalid literal for int() jacklee26 2 2,511 Feb-21-2020, 01:27 PM
Last Post: ndc85430
  ValueError: invalid literal for int() with base 10: '' Jay123 7 7,219 Aug-05-2019, 02:43 PM
Last Post: Jay123
  ValueError: invalid rectstyle object fen1c5 1 5,620 Jun-05-2019, 02:51 PM
Last Post: heiner55
  ValueError: invalid literal for int() with base 10: '' ivinjjunior 6 9,069 Apr-20-2019, 05:37 PM
Last Post: keames
  Problem with "invalid literal for int() with base 10: '' jirkaj4 4 10,387 Jan-23-2018, 06:55 PM
Last Post: jirkaj4

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020