I have a text file with the below numbers, strings and special characters.
63
148
77
358765
Orange
44.7
14
%
61
80
**
How to read the file and write into another file with only odd numbers.
Here's my rough code
with open("Odd-Numbers.txt", "r") as i:
with open("Output.txt", "w") as o:
odds = []
for num in i:
try:
num = int(num)
if num % 2:
odds.append(num)
except ValueError:
pass
for line in i:
output.write(line)
print(line, end = "")
It is giving me the error: invalid literal for int() with base 10: 'Mango\n'