Python Unexplained Invalid Literal Error (solution el alpha char at end of string) -
so i've looked @ other questions , answers error:
valueerror: invalid literal int() base of operations 10
all of them either because of empty string, string represented float, or string had quotes in it.
i'm getting error string should represent integer.
i wondering if had explanation of why happening?
input file:
1 10 123456789 3141592l
here's code:
import time start_time = time.time() import sys, math correct_set = {'0','1','2','3','4','5','6','7','8','9'} test = open(sys.argv[1]) n in test.readlines(): result_set = set() = 1 while true: current = str(int(n) * i) done = false char in current: if char not in result_set: result_set.add(char) if result_set == correct_set: print(i) done = true break if done: break += 1 print('time: {0} seconds'.format(time.time() - start_time))
output:
10 9 3 traceback (most recent phone call last): file "c:/users/shane/pycharmprojects/acm-practice/magic multiple/magic.py", line 11, in <module> current = str(int(n) * i) valueerror: invalid literal int() base of operations 10: '3141592l'
if add together print(repr(n)) in there get:
'3141592l'
which expected.
i tried dir(n) gave same result previous iterations.
any insight appreciated.
oh.. i'm on windows 8 running python 3.4 in pycharm.
the alpha character l (el) not 1 (one) lastly character in string "3141592l" you're trying convert! of interest, in illustration readlines() appending "\n" each line.
python python-3.4
No comments:
Post a Comment