Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Exercise 7: Program exercise for value-returning function Write a complete Python program including minimal comments (file name, your name, and problem description) that solves the

Exercise 7: Program exercise for value-returning function

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:

Write a program that reads a file name and the files contents, and determines the following:

The number of alphabetic (upper and lower case) letters in the file

The number of digits in the file

The number of lines in the file

Read a file name of a text file.

Catch any problem opening the file. If a problem occurs, print an error message and exit.

Make sure you have a main function and there should not be any global variable or statement other than the main function that is being called.

Create isAlpha function that receives a character and returns True if the letter is an alphabetic letter, otherwise it returns False.

Create isDigit function that receives a character and returns True if the letter is a digit, returns False otherwise.

Create the following data file as shown below and test your program.

Sample RUN #1: Enter the name of the file to open for read: file1.txt The number of alphabetic letters is 36 The number of digits is 3 The number of lines is 5 SAMPLE RUN #2: Enter the name of the file to open for read: coffee.txt The number of alphabetic letters is 77 The number of digits is 12 The number of line is 8 SAMPLE RUN #3: Enter the name of the file to open for read: filex.txt ERROR: filex.txt does not exist. 

SAMPLE input: file1.txt This is line 1. This is line 2. This is line 3. The end. SAMPLE input: coffee.txt Brazilian Dark Roast 18.5 Sumatra Medium Roast 25.0 Columbian Regular Roast 15.5 Columbian Medium Roast 20.0

image text in transcribed

Exercise 7: Program exercise for value-returning function 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: Write a program that reads a file name and the file's contents, and determines the following 1. The number of aphabetic (upper and lower case) letters in the file 2. The number of digits in the file 3. The number of lines in the file e Read a file name of a text file e Catch any problem opening the fle. If a problem occurs, print an error message and exit. e Make sure you have a main function and there should not be any global variable or statement other than the main function that is being called False. Create isDigit function that receives a character and returns True if the letter is a digit, returns False otherwise. e Create isAlpha function that receives a character and returns True if the letter is an alphabetic letter, otherwise it returns e Create the following data file as shown below and test your program. Sample RUN #1: Enter the name of the file t open for read: file1.txt The number of alphabetic letters is 36 The number of digits is 3 The number of lines is 5 SAMPLE RUN #2: Enter the name of the file topen for read: coffee.txt The number of alphabetic letters is 77 The number of digits is 12 The number of line is 8 SAIELE RUN #3: Enter the name of the file to open for read: filex.txt ERROR: filex.txt does not exist SAMPLE input: filel.txt This is line 1 This is line 2 This is line 3. The end SAMPLE input: coffee.txt Brazilian Dark Roast 18.5 Sumatra Medium Roast 25.0 Columbian Regular Roast 15.5 Columbian Medium Roast 20.0

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

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

Recommended Textbook for

Relational Database Technology

Authors: Suad Alagic

1st Edition

354096276X, 978-3540962762

More Books

Students also viewed these Databases questions

Question

Which statement about LSTM is NOT true?

Answered: 1 week ago