Question

2. Write a function file_copy() that takes two string parameters: in file and out_file and copies the contents of in_file into out file. Assume that in_file exists before file_copy is called. For example, the following would be correct input and output. 1 >>> file_copy( created equal.txt, copy.txt) 2 >>> open fopen ( copy.txt) 3 >>> equal-f = open( created-equal . txt) 4 >>equal_f.read () 5 We hold these truths to be self-evident, Inthat all men are created equalIn 3. Write: A program that implements a logbook, recording the visitors to a place of interest and their visits purpose. This log book could later be read by another program. Implement a function called log that takes one parameter, filename, the name of a file. You may assume the file is in the current working directory of the program. log should prompt the user for their name and the nature of their visit. log should then append a line to the file named filename in the following format: <NAME OF INDIVIDUAL> | <NATURE OF VISIT> Additional requirements: If the user enters empty input, or input that is only whitespace, re-prompt them for valid input before continuing. Your program must not remove previous lines from the file. For example, assume the following is the current contents of a file log.txt: 1Winston Churchill | The Queen is expecting me
media%2F1e8%2F1e8ba5f4-1c8d-4f62-b34b-54
0 0
Add a comment Improve this question Transcribed image text
Answer #1

1 def file_copy (in file, out_file): # o pening file to write open-f open (out_file, w) = 4 5 | # reading from file equal-f= open(in-file, r) 7 content equal_f.read() 8 9 | # writing content to out file 10 openf.write (content) 12 equal_f.close() 13 open f.close() 14 15 file_copy(created_equal.txt, copy.txt)

def file_copy(in_file, out_file):

# opening file to write

open_f = open(out_file, "w")

# reading from file

equal_f = open(in_file, "r")

content = equal_f.read()

# writing content to out_file

open_f.write(content)

equal_f.close()

open_f.close()

file_copy("created_equal.txt", "copy.txt")

Add a comment
Know the answer?
Add Answer to:
2. Write a function file_copy() that takes two string parameters: in file and out_file and copies...
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
  • Using python 1. Write: A program that implements a logbook, recording the visitors to a place...

    Using python 1. Write: A program that implements a logbook, recording the visitors to a place of interest and their visit's purpose. This log book could later be read by another program. Implement a function called log that takes one parameter, filename, the name of a file. You may assume the file is in the current working directory of the program. log should prompt the user for their name arid the nature of their visit. log should then append a...

  • C++ (1) Write a program to prompt the user for an input and output file name....

    C++ (1) Write a program to prompt the user for an input and output file name. The program should check for errors in opening the files, and print the name of any file which has an error, and exit if an error occurs. For example, (user input shown in caps in first line, and in second case, trying to write to a folder which you may not have write authority in) Enter input filename: DOESNOTEXIST.T Error opening input file: DOESNOTEXIST.T...

  • Problem 3 Write a function named repeat_words that takes two string parameters: 1. in_file: the name...

    Problem 3 Write a function named repeat_words that takes two string parameters: 1. in_file: the name of an input file that exists before repeat_words is called 2. out_file: the name of an output file that repeat_words creates Assume that the input file is in the current working directory and write the output file to that directory. For each line of the input file, the function repeat_words should write to the output file all of the words that appear more than...

  • A. File I/O using C library functions File I/O in C is achieved using a file...

    A. File I/O using C library functions File I/O in C is achieved using a file pointer to access or modify files. Processing files in C is a four-step process: o Declare a file pointer. o Open the desired file using the pointer. o Read from or write to the file and finally, o Close the file. FILE is a structure defined in <stdio.h>. Files can be opened using the fopen() function. This function takes two arguments, the filename and...

  • The name of the C++ file must be search.cpp Write a program that will read data...

    The name of the C++ file must be search.cpp Write a program that will read data from a file. The program will allow the user to specify the filename. Use a loop that will check if the file is opened correctly, otherwise display an error message and allow the user to re-enter a filename until successful. Read the values from the file and store into an integer array. The program should then prompt the user for an integer which will...

  • In c programming . Part A: Writing into a Sequential File Write a C program called...

    In c programming . Part A: Writing into a Sequential File Write a C program called "Lab5A.c" to prompt the user and store 5 student records into a file called "stdInfo.txt". This "stdInfo.txt" file will also be used in the second part of this laboratory exercise The format of the file would look like this sample (excluding the first line) ID FIRSTNAME LASTNAME GPA YEAR 10 jack drell 64.5 2018 20 mina alam 92.3 2016 40 abed alie 54.0 2017...

  • The input file should be called 'data.txt' and should be created according to the highlighted instructions...

    The input file should be called 'data.txt' and should be created according to the highlighted instructions below. Note that even though you know the name of the input file, you should not hard-code this name into your program. Instead, prompt the user for the name of the input file. The input file should contain (in order): the weight (a number greater than zero and less than or equal to 1), the number, n, of lowest numbers to drop, and the...

  • Write a menu based program implementing the following functions: (0) Write a function called displayMenu that...

    Write a menu based program implementing the following functions: (0) Write a function called displayMenu that does not take any parameters, but returns an integer representing your user's menu choice. Your program's main function should only comprise of the following: a do/while loop with the displayMenu function call inside the loop body switch/case, or if/else if/ ... for handling the calls of the functions based on the menu choice selected in displayMenu. the do/while loop should always continue as long...

  • Exercise 6: Program exercise for 2D List Write a complete Python program including minimal comments (file...

    Exercise 6: Program exercise for 2D List Write a complete Python program including minimal comments (file name, your name, and problem description) that solves the following problem with the main function: Problem Specification: The following code reads values from the file object infile and stores them in the 2d list table2: (It assumes that each line contains values of elements in each row and the values are whitespace separated.) table2 = [] for line in infile: row=line.split() intRow = []...

  • Function / File Read (USING MATLAB) A) create a user-defined function : [maxsample , maxvalue , numsamples]=writetofile(sname,strgth) to do the following: The user-defined function shall: -Accept as t...

    Function / File Read (USING MATLAB) A) create a user-defined function : [maxsample , maxvalue , numsamples]=writetofile(sname,strgth) to do the following: The user-defined function shall: -Accept as the input a provided string for the sample name (sname) and number for strength (strgth) - open a text file named mytensiledata.txt, with permission to read or append the file. - Make sure to capture any error in opening the file - Write sname and strgth to the file - Close the file...

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
Active Questions
ADVERTISEMENT