Create a python program Solve the problem statement below You will write a program to analyze characters in a text file. Create a file named text1.txt. Copy the lyrics given below into the text1.txt file. Make sure to save this file in the directory where you create your python file. Write a program that reads the text1.txt file's contents and calculates and outputs the following in this order: • The number of words in the file • The number of uppercase letters in the file • The number of lowercase letters in the file • The number of digits in the file
Create a python program Solve the problem statement below You will write a program to analyze characters in a text file. Create a file named text1.txt. Copy the lyrics given below into the text1.txt file. Make sure to save this file in the directory where you create your python file. Write a program that reads the text1.txt file's contents and calculates and outputs the following in this order: • The number of words in the file • The number of uppercase letters in the file • The number of lowercase letters in the file • The number of digits in the file
Chapter13: File Input And Output
Section: Chapter Questions
Problem 6PE
Related questions
Question
- Create a python program
- Solve the problem statement below
You will write a program to analyze characters in a text file. Create a file named text1.txt. Copy the lyrics given below into the text1.txt file. Make sure to save this file in the directory where you create your python file.
Write a program that reads the text1.txt file's contents and calculates and outputs the following in this order:
• The number of words in the file
• The number of uppercase letters in the file
• The number of lowercase letters in the file
• The number of digits in the file
• The number of whitespace characters in the file
NOTE: Your program should include at least one try-except error handling statement block.
Expert Solution
Step 1
try: with open('test.txt') as f: wordCount, upperCount, lowerCount, digitCount, spaceCount = 0, 0, 0, 0, 0 for line in f: line = line.strip() for ch in line: if ch.isupper(): upperCount += 1 if ch.islower(): lowerCount += 1 if ch.isdigit(): digitCount += 1 if ch.isspace(): spaceCount += 1 wordCount += len(line.split())
Trending now
This is a popular solution!
Step by step
Solved in 2 steps
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT