Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Heads or Tails: Python program Write a program that will prompt the user to enter a file name and the number of lines to extract

Heads or Tails: Python program

Write a program that will prompt the user to enter a file name and the number of lines to extract from that file name. When the number of lines is positive, the program will display the lines from the beginning of the file. When the number of lines is negative, the program will display the lines from the end of the file. If the number of lines exceeds the total number of lines in the file, then only the line count should be displayed.

Program Output:

Welcome to heads or tails file operations

This program accepts a file name and the number of lines. A positive number of lines displays from the beginning of the file.

A negative number of lines displays from the end of the file.

Enter the file name: lines10.txt

Enter a positive or a negative integer: -4

Below is the last -4 for the file: lines10.txt

Line 7

Line 8

Line 9

Line 10

>>>

Welcome to heads or tails file operations

This program accepts a file name and the number of lines. A positive number of lines displays from the beginning of the file.

A negative number of lines displays from the end of the file.

Enter the file name: lines10.txt

Enter a positive or a negative integer: 3

Below is the first 3 for the file: lines10.txt

Line 1

Line 2

Line 3

>>>

image text in transcribed

Program Output Shown below is the expected output produced by the program: Welcome to heads or tails file operations This program accepts a file name and the number of lines. A positive number of lines displays from the beginning of the file A negative number of lines displays from the end of the file. Enter the file name: lines10.txt Enter a positive or a negative integer: -4 Below is the last -4 for the file: lines10.txt Line 7 Line 8 Line 9 Line 10 >>> Welcome to heads or tails file operations This program accepts a file name and the number of lines. A positive number of lines displays from the beginning of the file A negative number of lines displays from the end of the file. Enter the file name: lines10.txt Enter a positive or a negative integer: 3 Below is the first 3 for the file: lines10.txt Line 1 Line 2 Line 3 Your output should look like the output above and everything should align correctly

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

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

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

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

Get Started

Recommended Textbook for

Murach's SQL Server 2012 For Developers

Authors: Bryan Syverson, Joel Murach, Mike Murach

1st Edition

1890774693, 9781890774691

More Books

Students also viewed these Databases questions

Question

How do Excel Pivot Tables handle data from non OLAP databases?

Answered: 1 week ago