I have some troubles with reading .txt file with numbers, I tried to do it in many ways but still getting error:
if x % 3 == 0:
TypeError: not all arguments converted during string formatting
Here are some numbers:
75158, 81917, 2318, 69039, 46112, 30323, 28184, 92597, 89159, 6579, 90155,
56960, 88247, 72470, 36266, 32693, 31542, 65354, 73315, 1440, 82950, 84901,
35835, 86530, 27137, 43235, 98977, 21224, 62530, 52675, 18297, 41055, 25597,
13878, 65430, 90050, 66844, 67605
Here is my code:
from string import punctuation
file=open("test.txt","r+")
lines=file.read()
xx=''.join(ch for ch in lines if ch not in punctuation)
print(xx)
for x in xx:
if x % 3 == 0:
print(x)
file.close()
I want to get printed all numbers divisible by 3.
While trying to make int from this string there is other error: invalid literal for int() with base 10: '75158....'