Question

Consider the following file arrest.dat containing information of a suspect that the police is looking for:...

Consider the following file arrest.dat containing information of a suspect that the police is looking for:
arrest.dat:
The police is looking for Robert Whiteshead, also known as Whity, ID number 4607091111027, from address 4 Azalea Court, 219 Belmont Street, Germiston, 2065, in connection with a bank robbery at UNITED BANK in January 2016. An amount of about R45,000,000 was stolen on this day. Apparently he had a helper that goes by the name of JOINT13. Mr Whiteshead was also an accomplice in a car syndicate in 2015 in Somerset-West. If anybody can supply any information that could lead to his arrest, please contact Sgt SURPRISE MOLOI at the Germiston police station on 011-2336767 or 011-2336788.
Your task is to write a program that will read the above file character by character, change certain characters, and create an output file that is written character by character. The following changes to the input characters should be made:
All uppercase characters are ignored and not written
Change characters read from the file as follows:

The rest of the characters remain the same, and are just written to the output file without any change (except for uppercase characters that are ignored).
Create file arrest.dat and ask the user to input the input and output file names.
Display the contents of the input and the output file on the screen.
Extra work. Directly change the arrest.dat file.
You should paste your answer(s) here for the question number in the heading. Remember to keep the current font size.

Homework Answers

Answer #1
file1 = input("Enter input file name:-")
file2 = input("Enter output file name:-")#taking input from user

def file_read(file_name): # reading content of file
    f = open(file_name, 'r')
    ip_file_content = f.read()
    print (ip_file_content)
    f.close()

print("input file content")
file_read(file1)

with open(file1,'r') as f:
    letter = ""
    l = []
    while True:
        letter = f.read(1)   #one letter at a time
        if letter.isupper():  # checking upperCase letter or not
            continue          # skip if l;etter is upper case
        else:
            l.append(letter)  # lower case write in output
        f2 = open(file2,'w')

        f2.write(str(''.join(l)))
        if not letter:
           break

print("output file content")
file_read(file2)

for extra credit

give input and output file name as arrest.dat

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT