Write a program that reads a text file and displays all the numbers found in the file in python
Code
# ask for file namefilename = input("Enter file name: ")# open file in read modef = open(filename, "r")# read the filedata = f.read()# display all the numbers in the filefor 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
0 Comments
Post a Comment