Question

In: Computer Science

Write a script named numberlines.py. This script creates a program listing from a source program. This...

Write a script named numberlines.py. This script creates a program listing from a source program.

This script should:

  1. Prompt the user for the names of two files.
    • The input filename could be the name of the script itself, but be careful to use a different output filename!
  2. The script copies the lines of text from the input file to the output file, numbering each line as it goes.
  3. The line numbers should be right-justified in 4 columns, so that the format of a line in the output file looks like this example:
   1> This is the first line of text.

Solutions

Expert Solution

CODE: Python Programming Language

# numberlines.py

input_filename = input('Enter input file name: ')
output_filename = input('Enter output file name: ')

with open(input_filename, 'r') as f, open(output_filename, 'w') as w:
    number = 0
    for line in f:
        number += 1
        w.write('{:>4}> {}'.format(number, line))

============================================================================

SCREENSHOT OF THE CODE:

============================================================================

INPUT:

numberlines.txt

This is the first line of text.

OUTPUT:

numberlines_output.txt

Thank you.


Related Solutions

Write a script that creates and calls a stored procedure named test. This procedure should identify...
Write a script that creates and calls a stored procedure named test. This procedure should identify all of the prime numbers less than 100. (A prime number is an integer that can't be divided by another integer other than 1 and itself.) Then, it should display a string variable that includes the prime numbers like this: 2 1 3 1 5 1 7 1 1 1 1 1 3 1 1 7 1 1 9 1 2 3 1 2...
SQL Code: Write a script that creates and calls a stored procedure named test. This procedure...
SQL Code: Write a script that creates and calls a stored procedure named test. This procedure should identify all of the prime numbers less than 100. (A prime number is an integer that can't be divided by another integer other than 1 and itself.) Then, it should display a string variable that includes the prime numbers like this: 2 1 3 1 5 1 7 1 1 1 1 1 3 1 1 7 1 1 9 1 2 3...
Write a program in a script file that creates m × n matrix with elements that...
Write a program in a script file that creates m × n matrix with elements that have the following values. The value of each element in the last row is the number of the column. The value of each element in the last column is the number of row +1. For the rest of the elements, each has a value equal to the sum of the element below it and the element to the right.
SQL Homework -- This script creates the schema named mgs -- Connect as the user named...
SQL Homework -- This script creates the schema named mgs -- Connect as the user named mgs --CONNECT cs270226mgs/mgs; -- Use an anonymous PL/SQL script to -- drop all tables and sequences in the current schema and -- suppress any error messages that may displayed -- if these objects don't exist BEGIN EXECUTE IMMEDIATE 'DROP SEQUENCE category_id_seq'; EXECUTE IMMEDIATE 'DROP SEQUENCE product_id_seq'; EXECUTE IMMEDIATE 'DROP SEQUENCE customer_id_seq'; EXECUTE IMMEDIATE 'DROP SEQUENCE address_id_seq'; EXECUTE IMMEDIATE 'DROP SEQUENCE order_id_seq'; EXECUTE IMMEDIATE 'DROP...
Write a program that creates an output file named rand_nums.txt. Open the file and write 100...
Write a program that creates an output file named rand_nums.txt. Open the file and write 100 random integers between -50 and +50 (inclusive) to the file. Be sure to handle any file IO exceptions. Remember to close the file. Write a program that opens rand_nums.txt for input. Create two output files pos.txt and neg.txt. Read through the input file, one line at a time, converting each line into an integer (no exception handling, yet). If the number is positive, write...
UNIX/LINUX SCRIPT: Create a named directory and verify that the directory is there by listing all...
UNIX/LINUX SCRIPT: Create a named directory and verify that the directory is there by listing all its contents. Write a shell script to validate password strength. Here are a few assumptions for the password string.   Length – a minimum of 8 characters. • Contain alphabets , numbers , and @ # $ % & * symbols. • Include both the small and capital case letters. give a prompt of Y or N to try another password and displays an error...
Program in Bash: Write a program using bash script that can read a file from the...
Program in Bash: Write a program using bash script that can read a file from the same directory, sort the nonrepeating integers from 0-9 from smallest to largest, and output the results on the same line. Do not use the sort function.
Program in Bash: Write a program using bash script that can read a file from the...
Program in Bash: Write a program using bash script that can read a file from the same directory, sort the nonrepeating integers from 0-9 from smallest to largest, and output the results on the same line. Do not use the sort function.
write a script named compute.sh that is used to do simple arithmetic for the user. There...
write a script named compute.sh that is used to do simple arithmetic for the user. There should be no command line arguments. Instead, all values from the user should be prompted for and read in to the script using the read command. Specifically, you need to ask the user for two integers and an operation string. The operation should be "add", "sub", "mul", "div", or "exp", for addition, subtraction, multiplication, division, and exponentiation, respectively. Your script should take the two...
Write a C program named as listLetterFreq.c that lists the frequency of the letters from the...
Write a C program named as listLetterFreq.c that lists the frequency of the letters from the input via ignoring the case sensitivity. For example, sample outputs could be like below. Please input a string: This is a list of courses. CSC 1010 - COMPUTERS & APPLICATION Here is the letter frequency: Letter a or A appears 3 times Letter b or B appears 0 times Letter c or C appears 5 times Letter d or D appears 0 times Letter...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT