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.

7. Ask the user to type the following lines (without bullet points) into Notepad++ and copy the lines to the clipboard (using Ctrl-c): • Line 1 from the clipboard • Line 2 from the clipboard • Line 3 from the clipboard

8. Programmatically display the contents of the clipboard which should contain the three lines from Requirement 7.

9. Read the contents of file_two.txt and read the contents of the clipboard.

10. Append the contents of the clipboard onto the contents of file_two.txt line-by-line to produce the following:
  • Line 1 from file_two correct_text followed by Line 1 from the clipboard
• Line 2 from file_two correct_text followed by Line 2 from the clipboard
• Line 3 from file_two correct_text followed by Line 2 from the clipboard

11. While performing Requirement 11, write the lines out to file_three.txt.

12. Display the contents of the file_three.txt.

13. Ask the user for a new directory name. Programmatically create that directory and programmatically copy the files created earlier in the program to the new directory. Programmatically compress the files in the new directory.

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

Please comment if you have any doubt

Code:

import os
import clipboard #install this module to work with clipboard
#type 'pip install clipboard' in cmd to do that
import shutil
#shutil is used to copy files
import zipfile
#zip file is used to work with zipfiles

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

#2 current working directory
currDir = os.getcwd()#getting the current working directory
print("Current working directory: ",currDir)

#3
makeDir=input("Enter Directory name to store files: ")
#if the directory already exists
#we need not to create that directory
#else we have to create that directory
if not os.path.exists(makeDir):
os.mkdir(makeDir)
#changing the directory
os.chdir(makeDir)

#4
#opening the file with write mode
file_one=open("file_one.txt","w")
#writing the content to file
file_one.write("Line 1 from file_one wrong_text\n")
file_one.write("Line 2 from file_one wrong_text\n")
file_one.write("Line 3 from file_one wrong_text\n")
file_one.close()

#5,6
file_one=open("file_one.txt","r")
file_two=open("file_two.txt","w")
for i in file_one:
#displaying the contents of file_one
print(i,end="")
#writing the replced text to file_two
file_two.write(i.replace("file_one wrong_text","file_two correct_text"))
file_one.close()
#closing the files
file_two.close()

#7
print("Please enter the below line in Notepad++ and copy the lines")
print('''Line 1 from the clipboard
Line 2 from the clipboard
Line 3 from the clipboard''')
cp_dt=clipboard.paste()#pasting the copied content
#8
print(cp_dt)

#9,10
dt=cp_dt.split('\n')#spillting the data with new line
file_two=open("file_two.txt","r")
txt=file_two.read().split('\n')#spillting the data with new line
new_txt=''
for i in range(3):
#appeding the new data
new_txt+=txt[i]+" followed by "+dt[i]

#11
file_three=open("file_three.txt","w")
file_three.write(new_txt)#writing the new data to text file
file_three.close()

#12
file_three=open("file_three.txt","r")
for i in file_three:
#printing the contents of file_three
print(i,end="")
file_three.close()

#13
newDir=input("\nEnter new directory name to copy files: ")
if not os.path.exists(newDir):
os.mkdir(newDir)
#files in first directory   
files=['file_one.txt','file_two.txt','file_three.txt']
for file in files:
shutil.copy(file,newDir)
#changing the direcotory to new directory
os.chdir(newDir)
for file in files:
#name of the new zip file
filename=file[:-4]+'.zip'
#creating a zip file and writing the data of current file
z= zipfile.ZipFile(filename, 'w')
#compress_type=zipfile.ZIP_DEFLATED will compress the file as zip
z.write(file,compress_type=zipfile.ZIP_DEFLATED)
z.close()

Screenshot:

Output:

import os import clipboard #install this module to work with clipboard #type 'pip install clipboard' in cmd to do that import shutil #shutil is used to copy files import zipfile #zip file is used to work with zipfiles #1 print ("This program manipulates text from files and the clipboard and performs other string, #2 current working directory currDir = os.getcwd () #getting the current working directory print ("Current working directory: ", currDir) #3 makeDir=input ("Enter Directory name to store files: ") #if the directory already exists #we need not to create that directory #else we have to create that directory if not os. path.exists (makeDir): os.mkdir (makeDir) #changing the directory os.chdir (makeDir) #4 #opening the file with write mode file one=open("file one.txt", "W") #writing the content to file file one.write("Line 1 from file one wrong text\n") file one.write("Line 2 from file one wrong text\n") file_one.write("Line 3 from file_one wrong_text\n") file_one.close()

#5,6 file one=open ("file one.txt","r") file two=open ("file two.txt", "w") for i in file one: #displaying the contents of file one print (i, end="") #writing the replced text to file_two file_two.write(i.replace("file_one wrong_text","file_two correct_text")) file one.close() #closing the files file two.close() #7 print("Please enter the below line in Notepad++ and copy the lines") print("''Line 1 from the clipboard Line 2 from the clipboard Line 3 from the clipboard''') cp dt=clipboard.paste () #pasting the copied content #8 print (cp_dt) #9,10 dt=cp_dt.split('\n') #spillting the data with new line file_two=open("file two.txt","r") txt=file_two.read().split('\n') #spillting the data with new line new txt='' for i in range (3): #appeding the new data new txt+=txt[i]+" followed by "+dt[i] #11 file three=open("file three.txt", "W") file three.write (new txt) #writing the new data to text file file three.close()

#12 file three=open ("file three.txt","r") for i in file three: #printing the contents of file_three print (i, end="") file three.close() #13 newDir=input("\nEnter new directory name to copy files: ") if not os. path.exists (newDir): os.mkdir (newDir) #files in first directory files=['file one.txt', 'file two.txt', 'file three.txt'] for file in files: shutil.copy (file, newDir) #changing the direcotory to new directory os.chdir (newDir) for file in files: #name of the new zip file filename=file [:-4]+'.zip' #creating a zip file and writing the data of current file z= zipfile.Zip File (filename, 'w') #compress_type=zipfile.ZIP_DEFLATED will compress the file as zip z.write(file, compress type=zipfile.ZIP DEFLATED) z.close()

We were unable to transcribe this image

Folder Name Date modified Type Size Folder 2 file_one.txt file_three.txt file_two.txt 29-03-2020 11:33 AM 29-03-2020 11:33 AM 29-03-2020 11:33 AM 29-03-2020 11:33 AM File folder Text Document Text Document Text Document 1 KB 1 KB 1 KB

Folder > Folder 2 Name Date modified Type Size 1 KB 1 KB file_one.txt file_one.zip file_three.txt file_three.zip file_two.txt file_two.zip 29-03-2020 11:33 AM 29-03-2020 11:33 AM 29-03-2020 11:33 AM 29-03-2020 11:33 AM 29-03-2020 11:33 AM 29-03-2020 11:33 AM Text Document WinRAR ZIP archive Text Document WinRAR ZIP archive Text Document WinRAR ZIP archive 1 KB

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...

  • using lubuntu ce the following activities on your Linux virtual machine. Then complete estions. Write a script file which when executed will perform the following: First display today's date in d...

    using lubuntu ce the following activities on your Linux virtual machine. Then complete estions. Write a script file which when executed will perform the following: First display today's date in dd.mm.YYYY format (e.g. 20.04.2019). Ask user to enter a name to create a directory. Create a directory by the given directory name above. . . Ask user to enter a name to create a file. Copy the file /etc/passwd to the given filename above inside the newly created directory Copy...

  • 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...

  • Write a python program that prompts the user for the names of two text files and...

    Write a python program that prompts the user for the names of two text files and compare the contents of the two files to see if they are the same. If they are, the scripts should simply output “Yes”. If they are not, the program should output “No”, followed by the first lines of each file that differ from each other. The input loop should read and compare lines from each file. The loop should break as soon as a...

  • Create a New Java Project called YourLastNameUpperCase. Write a program that asks the user for the...

    Create a New Java Project called YourLastNameUpperCase. Write a program that asks the user for the names of two files. The first file should be opened for reading and the second file should be opened for writing. The program should read the contents of the first file, change all characters to uppercase, and store the results in the second file. The second file will be a copy of the first file, except that all the characters will be uppercase. Use...

  • 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)...

  • SHELL SCRIPT: Provide the following questions with the codes and command line Problem 5: Take 5...

    SHELL SCRIPT: Provide the following questions with the codes and command line Problem 5: Take 5 input arguments in a for loop, but only add the even i values to sum and display the result. Problem 6: Write a shell script that accepts path of the directory and returns a count of all the files within the specified directory. (Hint: use alias to perform cd operation) Problem 7: Write a shell script that takes an ‘count’ value as an input...

  • Creating a Shell Interface Using Java This project consists of modifying a Java program so that...

    Creating a Shell Interface Using Java This project consists of modifying a Java program so that it serves as a shell interface that accepts user commands and then executes each command in a separate process external to the Java virtual machine. Overview A shell interface provides the user with a prompt, after which the user enters the next command. The example below illustrates the prompt jsh> and the user’s next command: cat Prog.java. This command displays the file Prog.java on...

  • 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...

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