Question

python

python

Complete the below function that takes the name of two files, inFilename and

outFilename as arguments and reads the text from the inFilename. In this file

each line contains the Turkish Republic Identity Number (TCNO), name, surname

and telephone number of a person. Your function should sort all persons

according to their TCNO, write the sorted data into outFilename. If the file

inFilename does not exist, then the function must create an empty file named

outFilename.

For example, if the function is called such as

readText("in.txt", "out.txt")

and in.txt is as follows:

===== in.txt =====

12345678904 Barış Manço 0555-999-99-66

12345678902 Ahmet Kaya 0555-999-99-88

12345678901 Burkay Genç 0555-999-99-99

12345678903 Erkin Koray 0555-999-99-77

==================

Then, the function writes the sorted information into "out.txt" as follows:

===== out.txt =====

12345678901 Burkay Genç 0555-999-99-99

12345678902 Ahmet Kaya 0555-999-99-88

12345678903 Erkin Koray 0555-999-99-77

12345678904 Barış Manço 0555-999-99-66

==================

You can assume that TCNO and the phone number will be provided as a block,

without any spaces. You can also assume that the persons have just one name.

Note that inFilename and outFilename are the names of arguments of the function.

They are strings, and the values of the strings are the actual file names. For

example, if the function is called such as:

readText("file1.txt", "file2.txt")

then, you must read the content from "file1.txt" and write the output to

"file2.txt".

"""

def readText(inFilename,outFilename):

    return # Delete this line to answer this question


0 0
Add a comment Improve this question Transcribed image text
Request Professional Answer

Request Answer!

We need at least 9 more requests to produce the answer.

1 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the answer will be notified once they are available.
Know the answer?
Add Answer to:
python
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • Homework 1- Merge Files: 1. Design a class named MergeFiles 1 Three file names are passed...

    Homework 1- Merge Files: 1. Design a class named MergeFiles 1 Three file names are passed as command-line arguments to MergeFiles as follows: java MergeFiles filel file2 mergedFile II. MergeFiles reads names stored in files file and file2 III. Merges the two list of names into a single list IV. Sorts that single list V. Ignores repetitions VI. Writes the sorted, free-of-repetitions list to a new file named mergedFile.txt VII. The names in all three files are stored as one...

  • Objective: Use input/output files, strings, and command line arguments. Write a program that processes a text...

    Objective: Use input/output files, strings, and command line arguments. Write a program that processes a text file by removing all blank lines (including lines that only contain white spaces), all spaces/tabs before the beginning of the line, and all spaces/tabs at the end of the line. The file must be saved under a different name with all the lines numbered and a single blank line added at the end of the file. For example, if the input file is given...

  • Please write the following code as simple as possible in python: You will need to define...

    Please write the following code as simple as possible in python: You will need to define a function with four arguments. Here is what I used: > def find_matches(file1.txt, output1.txt, strings, value): file1.txt will contain a list of various strings. The program must copy from the first argument, and it should be written in the second argument (the second file, "output1.txt"). The third and fourth arguments will determine which specific strings will be copied over to the second file. For...

  • This assignment uses functions, files, and strings. Enough flexibility is provided for you to apply your...

    This assignment uses functions, files, and strings. Enough flexibility is provided for you to apply your knowledge of basic C++ programing to develop your solution. Develop a functional flowchart and then write a C++ program to solve the following problem. 1. Create a text file named file1.txt and write your brand of car (like Honda, Toyota, etc) in the file. You will be reading the name of the file from the keyboard as a string, using the string class. Your...

  • (IN PYTHON) You are to develop a Python program that will read the file Grades-1.txt that...

    (IN PYTHON) You are to develop a Python program that will read the file Grades-1.txt that you have been provided on Canvas. That file has a name and 3 grades on each line. You are to ask the user for the name of the file and how many grades there are per line. In this case, it is 3 but your program should work if the files was changed to have more or fewer grades per line. The name and...

  • For this problem, you have to use following hash function: key modulo the number of buckets....

    For this problem, you have to use following hash function: key modulo the number of buckets. Input format: This program takes a file name as argument from the command line. The file is either blank or contains successive lines of input. Each line contains a character, either ‘i’ or ‘s’, followed by a tab and then an integer, the same format as in the Second Part. For each of the lines that starts with ‘i’, your program should insert that...

  • using python The following shows the result of calling function read_from_file_sum_squares() for each of these two...

    using python The following shows the result of calling function read_from_file_sum_squares() for each of these two files: >>> from praco import read_from_file_sum_squares >>> read_from_file_sum_squares () Enter the filename: file1 9 >>> read_from_file_sum_squares () Enter the filename: file2 14 20 1 >>> You can use file = open(filename, "r") to open the file named by string filename to read, and the line list_lines = file.readlines() to store in list_lines the list of strings, where each string is a line of the...

  • PYTHON 4. Define a function that takes two arguments: a string called strText and a number...

    PYTHON 4. Define a function that takes two arguments: a string called strText and a number called intNumber. This function will use a repetition structure (a While or For loop) to print strText intNumber of times. Call this function. 5. Get an input from the user that is a file name with an extension (e.g., "myfile.ipynb" or "myfile.txt"). Print only the characters that follow the "." in the file name (e.g., "ipynb" and "txt"). 6. Ask the user for 5...

  • For each problem, you must: Write a Python program Test, debug, and execute the Python program...

    For each problem, you must: Write a Python program Test, debug, and execute the Python program Save your program in a .py file and submit your commented code to your Student Page. Note regarding comments: For every class, method or function you create, you must provide a brief description of the what the code does as well as the specific details of the interface (input and output) of the function or method. (25 pts.) Write a program that reads in...

  • Need some help on this Python Problem called "unique words" the text.txt file can be any...

    Need some help on this Python Problem called "unique words" the text.txt file can be any .txt file with words in it. Write a program that opens a specified text file and then displays the number of unique words in the text file after stripping all the white spaces, comma, and the punctuation marks and list of all the unique words found in the file. The list should be sorted in alphabetical order. The program should handle the ‘file not...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT