Fill This Form To Receive Instant Help
Homework answers / question archive / Problem: Write a program that prompts for the names of a source file to read and a target file to write, and copy the content of the source file to the target file, but get all empty lines removed, then output the number of empty lines removed
Problem: Write a program that prompts for the names of a source file to read and a target file to write, and copy the content of the source file to the target file, but get all empty lines removed, then output the number of empty lines removed. For example: Source file name: string_doc.txt Target file name: string_doc_nonempty.txt Lines removed: 16 1 3.2 Problem 2 (1 mark) Problem: Write a program that prompts for the name of a file, then print the first two lines and the last two lines of the file. For example: File name: yesterday.txt Output: Yesterday Once More When I was young I would sing to then And I’d memorize each Hint: the lines in a file are ended with a new line unless it is the last line. 3.3 Problem 3 (1 mark) Problem: Write a program that prompts for the name of a file containing numbers in each line, prints the average of each line. Assume each line contains numbers only and they are separated by spaces. For example: File The The The The name: scores.txt average of line 1 average of line 2 average of line 3 average of line 4 is is is is 60.0 91.75 48.75 56.25 3.4 Problem 4 (1 mark) Problem: The Unix tool wc counts the numbers of characters, words and lines in a file. Write your own version of wc that prompts for the name of the file to read, then prints the counts. Assume a word may contain letters, digits, symbols and their mixture, but not space. Hyphenated words, e.g. large-scale, shall be considered as one word. For example: File name: python.txt Characters: 1227 Words: 176 Lines: 10 2 50 60 70 60 100 90 87 90 30 65 50 50 58 50 74 43 1 Yesterday Once More When I was young I’d listen to the radio Waitin’ for my favorite songs When they played I’d sing along It made me smile. Those were such happy times And not so long ago How I wondered where they’d gone But they’re back again Just like a long lost friend All the songs I loved so well. Every Sha-la-la-la Every Wo-o-wo-o Still shines Every shing-a-ling-a-ling That they’re startin’ to sing’s So fine. When they get to the part Where he’s breakin’ her heart It can really make me cry Just like before It’s yesterday once more. Lookin’ back on how it was In years gone by And the good times that I had Makes today seem rather sad So much has changed. It was songs of love that I would sing to then And I’d memorize each 1 Python is an interpreted high-level general-purpose programming language. Python’s design philosophy emphasizes code readability with its notable use of significant indentation. Its language constructs as well as its object-oriented approach aim to help programmers write clear, logical code for small and largescale projects. Python is dynamically-typed and garbage-collected. It supports multiple programming paradigms, including structured (particularly, procedural), object-oriented and functional programming. Python is often described as a “batteries included” language due to its comprehensive standard library. Guido van Rossum began working on Python in the late 1980s, as a successor to the ABC programming language, and first released it in 1991 as Python 0.9.0. Python 2.0 was released in 2000 and introduced new features, such as list comprehensions and a garbage collection system using reference counting and was discontinued with version 2.7.18 in 2020. Python 3.0 was released in 2008 and was a major revision of the language that is not completely backward-compatible and much Python 2 code does not run unmodified on Python 3. Python consistently ranks as one of the most popular programming languages.