question archive def backup_file():   """Makes a backup of a file

def backup_file():   """Makes a backup of a file

Subject:Computer SciencePrice:2.86 Bought7

def backup_file():

  """Makes a backup of a file. Your program should

  prompt the user for the name of the file to copy and then write a new file

  with the same contents but with .bak as the file extension

  Args: None

  Return: None

  This should create another file in your folder

  You can use alkaline.txt to create backup alkaline.txt.bak

  """

  # take input from the user asking which file would they like to backup?

  # store the name of file in new variable, filename

  filename = 'alkaline.txt'

  # create new filename with .bak extension by adding filename + '.bak'

  filename = 'alkaline.txt.bak'

  # Open new filename in 'w' mode

  with open filename as f:

  # loop over file you would like to backup

  # use .write() to write each line in old file into new backup file

 

  # close the file

  pass

 

pur-new-sol

Purchase A New Answer

Custom new solution created by our subject matter experts

GET A QUOTE

Answer Preview

def backup_file():
    """Makes a backup of a file. Your program should
    prompt the user for the name of the file to copy and then write a new file
    with the same contents but with .bak as the file extension
    Args: None
    Return: None
    This should create another file in your folder
    You can use alkaline.txt to create backup alkaline.txt.bak
    """
    # take input from the user asking which file would they like to backup?
    # store the name of file in new variable, filename
    # create new filename with .bak extension by adding filename + '.bak'

    # Open new filename in 'w' mode

    # loop over file you would like to backup
    # use .write() to write each line in old file into new backup file

    # close the file
    f_name = input("Enter the name of file to backup: ")

    with open(f_name , 'r') as _file:
        file = _file.read()
    file = file.split("\n")
    fr = open(f_name+".bak", 'w')
    for i in file:
        fr.write(i+"\n")
    fr.close()