(6) Write a python program that asks the user for two filenames and calls your function copy_even_lines() from (5) using those two filenames. If one or more files do not exist, your program must handle the exception by repeating the prompts until valid filenames are entered.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

The programe code is (5) thats being reffered.

(6) Write a python program that asks the user for two filenames and calls your function copy_even_lines() from (5) using those two filenames. If one or more files do not exist, your program must handle the exception by repeating the prompts until valid filenames are entered.

(6) Write a python program that asks the user for two filenames and calls your function
copy_even_lines() from (5) using those two filenames. If one or more files do not
exist, your program must handle the exception by repeating the prompts until valid
filenames are entered.
Transcribed Image Text:(6) Write a python program that asks the user for two filenames and calls your function copy_even_lines() from (5) using those two filenames. If one or more files do not exist, your program must handle the exception by repeating the prompts until valid filenames are entered.
File
Edit Selection View
Go
Run
Terminal Help
prac5.py - Workshop - Visual Studio Code
ệ practiceeee.py
ệ prac2.py
e PP T2Q3.py
ệ prac4.py
ệ prac5.py
E Test.txt
E file_name.txt
EXPLORER
...
v WORKSHOP
C: > Users > usama > OneDrive > Desktop > Programming > Uni > Tutorials > 101205034_T7 > ở prac5.py > ..
E file_name.txt
1
def copy_even_lines(string1, string2):
E Test.txt
2
# to clear the content of file2
with open(string2, 'r+') as f2:
f2.truncate(0)
3
4
# find the even line data from file1 and write it into file2
7
with open(string1, 'r') as f1:
8
count = 0
for line in f1:
10
count+=1
11
if count % 2 == 0:
A
with open(string2, 'a') as f2:
f2.write(line)
f2.close()
12
13
14
15
# 1st argument file1 from you want to copy the data
# 2nd argument file2 in which you want to write the copied data
copy_even_lines("Test.txt","file_name.txt")
16
17
18
OUTLINE
Python 3.9.7 64-bit
O 0 A 0
Ln 18, Col 44 Spaces: 4
UTF-8
Python O
CRLF
ENG
4:12 AM
US
2021-11-18
Transcribed Image Text:File Edit Selection View Go Run Terminal Help prac5.py - Workshop - Visual Studio Code ệ practiceeee.py ệ prac2.py e PP T2Q3.py ệ prac4.py ệ prac5.py E Test.txt E file_name.txt EXPLORER ... v WORKSHOP C: > Users > usama > OneDrive > Desktop > Programming > Uni > Tutorials > 101205034_T7 > ở prac5.py > .. E file_name.txt 1 def copy_even_lines(string1, string2): E Test.txt 2 # to clear the content of file2 with open(string2, 'r+') as f2: f2.truncate(0) 3 4 # find the even line data from file1 and write it into file2 7 with open(string1, 'r') as f1: 8 count = 0 for line in f1: 10 count+=1 11 if count % 2 == 0: A with open(string2, 'a') as f2: f2.write(line) f2.close() 12 13 14 15 # 1st argument file1 from you want to copy the data # 2nd argument file2 in which you want to write the copied data copy_even_lines("Test.txt","file_name.txt") 16 17 18 OUTLINE Python 3.9.7 64-bit O 0 A 0 Ln 18, Col 44 Spaces: 4 UTF-8 Python O CRLF ENG 4:12 AM US 2021-11-18
Expert Solution
steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
File Input and Output Operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education