Write a program that reads a text file and displays all the numbers found in the file in python

Code

# ask for file name
filename = input("Enter file name: ")

# open file in read mode
f = open(filename, "r")

# read the file
data = f.read()

# display all the numbers in the file

for char in data:
if char.isdigit():
print(char)
f.close()


Output

Enter file name: test.txt
5
4
9
3
3
4
2
0
6
9
3
0
0
0