invalid literal for int with base 10

0 votes

In order to create a program which can read the file and the starting line on the file is not empty or blank, which further enables the next four lines to be deciphered, what must one do? The calculations are performed on the lines and then the next line is readable. However, if that line isn’t empty, it still continues. However, this error persists:


ValueError: invalid literal for int() with base 10
 

Despite being able to understand and read the line at the start, the process of converting it to an integer is not working for me. What can I do to fix this problem?

file_to_read = raw_input("Enter file name of tests (empty string to end program):") 
try: infile = open(file_to_read, 'r') 
while file_to_read != " ": 
file_to_write = raw_input("Enter output file name (.csv will be appended to it):") 
file_to_write = file_to_write + ".csv" 
outfile = open(file_to_write, "w") 
readings = (infile.readline()) 
print readings 
while readings != 0: 
global count 
readings = int(readings) 
minimum = (infile.readline()) 
maximum = (infile.readline())
Feb 8, 2022 in Python by Rahul
• 9,680 points
1,249 views

1 answer to this question.

0 votes

In order to solve this problem, one must use the following lines of code:-
 

>>> int('55063.000000') 
Traceback (most recent call last): 
File "<stdin>", line 1, in <module> 
ValueError: invalid literal for int() with base 10: '55063.000000'


Which brings the user to this and must be used to avoid the problem of non conversion to the integer:-
 

>>> int(float('55063.000000')) 55063
answered Feb 8, 2022 by Soham
• 9,710 points

Related Questions In Python

+2 votes
10 answers

How to fix this? ValueError: invalid literal for int() with base 10 error in Python

The following are totally acceptable in python: passing ...READ MORE

answered Nov 16, 2018 in Python by Nymeria
• 3,560 points
409,377 views
0 votes
1 answer

Error is "invalid literal for int() with base 10: ' ' "

This error is caused because we try ...READ MORE

answered Oct 15, 2020 in Python by Gitika
• 65,770 points
2,926 views
0 votes
1 answer

invalid literal for int() with base 10 in python

Hello, You can try this simple code: def getSum(n): ...READ MORE

answered Nov 23, 2020 in Python by Niroj
• 82,840 points
2,108 views
0 votes
1 answer

OSX 10.11 with py2app?

I'm not sure if this is your ...READ MORE

answered May 9, 2018 in Python by charlie_brown
• 7,720 points
1,462 views
0 votes
1 answer

'Syntax Error: invalid syntax' for no apparent reason

You're missing a close paren in this ...READ MORE

answered Aug 13, 2018 in Python by Priyaj
• 58,020 points
2,478 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,466 views
0 votes
1 answer
0 votes
2 answers

Replacements for switch statement in Python?

The recommended path for Python 3.10 which ...READ MORE

answered Feb 9, 2022 in Python by Soham
• 9,710 points
892 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP