Question

***This program is to be created using PyCharm Pro*** 1. Print “This program manipulates text from...

***This program is to be created using PyCharm Pro***

1. Print “This program manipulates text from files and the clipboard and performs other string, file, and directory manipulation tasks.”

2. Output the current working directory of the program.

3. Ask the user to enter the directory where they would like files to be stored, make that directory, and store files in the program in that directory.

4. Write the following three lines to file_one.txt (without bullet points):
• Line 1 from file_one wrong_text
  • Line 2 from file_ one wrong_text
  • Line 3 from file_ one wrong_text

5. Display the contents of file_one.txt.

6. Programmatically replace the substring ‘file_one wrong_text’ in data read from file_one.txt with ‘file_two correct_text’ and write the corrected lines to file_two.txt.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks

Note: Please maintain proper code spacing (indentation), just copy the code part and paste it in your compiler/IDE directly, no modifications required.

#code

import os

#displaying greeting
print("This program manipulates text from files and the clipboard and performs other string,"
      " file, and directory manipulation tasks.")

#displaying current working directory
print('\nCurrent working directory:',os.getcwd())
#reading name of directory to store files
dir_name=input('Enter the directory where you would like files to be stored: ')

#creating the directory, only if the directory does not exist already
if not os.path.exists(dir_name):
      os.mkdir(dir_name)
#moving to the above directory
os.chdir(dir_name)

#opening file_one.txt file in write mode
file1=open('file_one.txt','w')
#writing the three required lines
file1.write('Line 1 from file_one wrong_text\n')
file1.write('Line 2 from file_one wrong_text\n')
file1.write('Line 3 from file_one wrong_text\n')
#closing and saving file
file1.close()

#opening the same file in read mode
file1=open('file_one.txt','r')
#reading whole text into a variable
data=file1.read()
#displaying the contents
print('Contents of file_one.txt:')
print(data)
#closing file
file1.close()

#replacing 'file_one wrong_text' with 'file_one correct_text'
data=data.replace('file_one wrong_text','file_one correct_text')
#opening file_two.txt in write mode
file2=open('file_two.txt','w')
#writing updated text
file2.write(data)
#closing and saving file
file2.close()

#output

#file_two.txt

Add a comment
Know the answer?
Add Answer to:
***This program is to be created using PyCharm Pro*** 1. Print “This program manipulates text from...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • ***This program is to be created using PyCharm Pro*** 1. Print “This program manipulates text from...

    ***This program is to be created using PyCharm Pro*** 1. Print “This program manipulates text from files and the clipboard and performs other string, file, and directory manipulation tasks.” 2. Output the current working directory of the program. 3. Ask the user to enter the directory where they would like files to be stored, make that directory, and store files in the program in that directory. 4. Write the following three lines to file_one.txt (without bullet points): • Line 1...

  • Must be done in python and using linux mint Write a program to create a text...

    Must be done in python and using linux mint Write a program to create a text file which contains a sequence of test scores. Each score will be between 0 and 100 inclusive. There will be one value per line, with no additional text in the file. Stop adding information to the file when the user enters -1 The program will first ask for a file name and then the scores. Use a sentinel of -1 to indicate the user...

  • Really need help from 11 on: Create the directory structure IFT383FinalExam/Activities/Activity1 in your home directory. Using...

    Really need help from 11 on: Create the directory structure IFT383FinalExam/Activities/Activity1 in your home directory. Using the cat command, create a file named classRoster with the following fields, separated by a comma. Student ID First Name Last Name Grade Program of Study ASURITE ID (username) Add three records to your file. Display the contents of the file. Move the file classRoster to the directory Activity1. Go to the Activity1 directory. Display the directory you are in. Add read, write and...

  • Hi, I need help for solving Linux question. . 1.Using the proper text editor, create a...

    Hi, I need help for solving Linux question. . 1.Using the proper text editor, create a shell file called by (your name), your enrollment number, your program and the courses you study. Use the appropriate variables and display the above to the standard output (screen). . 2. Write A Shell Script to perform the following: Display the files and directories Print the date in 24 hour format Display the System id Display the current working directory Print the status of...

  • Write a python program and pseudocode The Program Using Windows Notepad (or similar program), create a...

    Write a python program and pseudocode The Program Using Windows Notepad (or similar program), create a file called Numbers.txt in your the same folder as your Python program. This file should contain a list on floating point numbers, one on each line. The number should be greater than zero but less than one million. Your program should read the following and display: The number of numbers in the file (i.e. count them) (counter) The maximum number in the file (maximum)...

  • Write a C++ program that reads text from a file and encrypts the file by adding...

    Write a C++ program that reads text from a file and encrypts the file by adding 6 to the ASCII value of each character. See section 5.11 in Starting out with C++ for information on reading and writing to text files. Your program should: 1. Read the provided plain.txt file one line at a time. Because this file has spaces, use getline (see section 3.8). 2. Change each character of the string by adding 6 to it. 3. Write the...

  • Write a program that performs the following: - Reads from the file "myfile.txt" using readlines() -...

    Write a program that performs the following: - Reads from the file "myfile.txt" using readlines() - Prints out the contents of the file "myfile.txt", that was read into a list by readlines(). Note that this should not look like a list, so you will need to loop through the list created by readlines and print the text. - Use the try/except method to create the file if it does not exist - If the file does not exist, prompt the...

  • LINUX QUESTIONS (dont have to display output, I will be running these commands myself to check...

    LINUX QUESTIONS (dont have to display output, I will be running these commands myself to check the output) Display the command(s) used to do the following: create an empty file called history by using just a redirection operator. Verify and show. Show/verify all results (i.e., all commands and their corresponding outputs). Wait 1 minute or more and then display the command(s) used to do the following: change the timestamp on the history file you just created. Verify/display the change. Show/verify...

  • What to submit: your answers to exercises 2. Write a Java program to perform the following...

    What to submit: your answers to exercises 2. Write a Java program to perform the following tasks: The program should ask the user for the name of an input file and the name of an output file. It should then open the input file as a text file (if the input file does not exist it should throw an exception) and read the contents line by line. It should also open the output file as a text file and write...

  • Lab #10 C++ Write a C++ program that reads text from a file and encrypts the...

    Lab #10 C++ Write a C++ program that reads text from a file and encrypts the file by adding an encryption factor (EF) to the ASCII value of each character. The encryption factor is 1 for the first line and increases by 1 for each line up to 4 and then starts over at 1. So, for the 4 th line the EF is 4, for the 5th line it is 1, for the 10th line it is 2. In...

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