Problem B
Get Numbers From File
Write a program that extracts all numbers from a given text file. The results should be saved in a list and finally printed out in sorted order.
First, the program should ask the user for a file name, repeatedly until the user enters a name of a file that actually exists, as evidenced by the fact that it can be opened. The file will be located in the /src/ directory.
Input
The input consists of one or more line. At least one line will contain the name of a file that is accessible to the program.
To be specific, the input will consist of
Note that in the samples below, the content of the files is
not shown. See the provided text files for more information.
The input files will consist of
Output
The output should consist of
For each
-
“{
} not found! Please try again.”
Finally, the last line should contain an ordered list of all
numbers found in the file
As soon as the program receives a name of a file that it can
open, it should stop asking for input and process the file.
Note that this means
Sample Input 1 | Sample Output 1 |
---|---|
Arc of the covenant Aristotle's second book of Poetics Confucius' Classic of Music Book of Thoth Amelia Earhart Holy grail Oceanic Airlines Flight 815 number_text.txt |
Arc of the covenant not found! Please try again. Aristotle's second book of Poetics not found! Please try again. Confucius' Classic of Music not found! Please try again. Book of Thoth not found! Please try again. Amelia Earhart not found! Please try again. Holy grail not found! Please try again. Oceanic Airlines Flight 815 not found! Please try again. [1, 3, 5, 7, 10, 77] |
Sample Input 2 | Sample Output 2 |
---|---|
number_text_alternative.txt number_text.txt |
[1, 3, 15, 734] |
Sample Input 3 | Sample Output 3 |
---|---|
yet_another_number_text.txt |
[0, 1] |
Sample Input 4 | Sample Output 4 |
---|---|
test_file_02 test_file_02.txt |
test_file_02 not found! Please try again. [698, 1099, 2155, 4955, 6153, 6722, 7824, 8384, 9454, 9947] |