Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can you please do it in python Programming Exercises 2. Flle Head Display Write a program that asks the user for the name of a

Can you please do it in python image text in transcribed
Programming Exercises 2. Flle Head Display Write a program that asks the user for the name of a file. The program should display only the first five lines of the file's contents. If the file contains less than five lines, it should display the file's entire contents 3. Line Numbers Write a program that asks the user for the name of a file. The program should display the contents of the file with each line preceded with a line number followed by a colon. The line numbering should start at 1 4. Item Counter Assume that a file containing a series of names (as strings) is named nanes.txt and exists on the computer's disk. Write a program that displays the number of names that are stored in the file. (Hint: Open the file and read every string stored in it. Use a variable to keep a count of the macmber of items that are read from the file 5. Sum of Numbers Assume that a file containing a series of integers is named numbers.txt and exists on the computer's disk. Write a program that reads all of the numbers stored in the file and cal- culates their total. 6. Average of Numbers Assume that a file containing a series of integers is named nunbers.ext and exists on the computer's disk. Write a program that calculates the average of all the numbers stored in the file. 7. Random Number File Writer Write a program that writes a series of random numbers to a file. Each random number should be in the range of 1 through 500. The application should let the user specify how many random numbers the file will hold 8. Random Number File Reader This exercise assumes you have completed Programming Exercise 7, Randome Namber Fie Writer. Write another program that reads the random numbers from the file, display the numbers, and then display the following data: The total of the numbers The number of random numbers read from the file . 9. Exception Handing Modify the program that you wrote for Exercise 6 so it handles the following exceptions It should handle any rOError exceptions that are raised when the file is opened and data is read from it. It should handle any valuetrror exceptions that are raised when the inems that are read from the file are converted to a number

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions