Question
i need the answer for this python question using dictionary method please!!!
points) Attached to the Exam #4 code Assignment in Tracs you ## will find a file, text.txt. Text is stored 1 sentence per l
0 0
Add a comment Improve this question Transcribed image text
Answer #1

dict = {} #initializing a dictionary
dict['UpperCase_Characters'] = 0 # with a key to store number of uppercase characters
dict['LowerCase_Characters'] = 0 # with a key to store number of lowercase characters
dict['Digits'] = 0 # with a key to store number of digits
dict['WhiteSpace_Characters'] = 0 # with a key to store number of whitespace characters
with open('temp.txt','r') as file: #opening a text file in read mode
for line in file: #takes one line at a time
for i in list(line): #converting the line into a list of characters
try: #since int(i) for special characters will result in a exception
if i.isupper(): # if uppercase
dict['UpperCase_Characters'] += 1
elif i.islower(): # if lowercase
dict['LowerCase_Characters'] += 1
elif i == ' ': # if whitespace
dict['WhiteSpace_Characters'] += 1
elif int(i): # if integer
dict['Digits'] += 1
except:
continue #since it is not uppercase or lowercase
# or whitespace or integer go to next loop
#printing the contents of the dictionary
print("\nNumber of Uppercase characters in the file: ",dict['UpperCase_Characters'])
print("\nNumber of Lowercase characters in the file: ",dict['LowerCase_Characters'])
print("\nNumber of Digits in the file: ",dict['Digits'])
print("\nNumber of Whitespace characters in the file: ",dict['WhiteSpace_Characters'])

#Input file ->

Writers write descriptive paragraphs because their purpose is to describe something.
Their point is that something is beautiful or disgusting or strangely intriguing.
Writers write persuasive and argument paragraphs because their purpose is to persuade or convince someone.
Their point is that their reader should see things a particular way and possibly take action on that new way of seeing things.
Writers write paragraphs of comparison because the comparison will make their point clear to their readers.

Add a comment
Know the answer?
Add Answer to:
i need the answer for this python question using dictionary method please!!! points) Attached to the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • python question! points) Attached to the Exam #4 code Assignment in Tracs you ## will find...

    python question! points) Attached to the Exam #4 code Assignment in Tracs you ## will find a file, "text.txt". Text is stored 1 sentence per line. ## Write a program below that reads the file contents and displays ## the following: ## 1. Number of uppercase characters in the file ## 2. Number of lowercase characters in the file ## 3. Number of digits in the file. ## 4. Number of whitespace characters in the file ## ## print("Number of...

  • Python Programming 4th Edition: Need help writing this program below. I get an error message that...

    Python Programming 4th Edition: Need help writing this program below. I get an error message that says that name is not defined when running the program below. My solution: def main(): filename = "text.txt" contents=f.read() upper_count=0 lower_count=0 digit_count=0 space_count=0 for i in contents: if i.isupper(): upper_count+=1 elif i.islower(): lower_count+=1 elif i.isdigit(): digit_count+=1 elif i.isspace(): space_count+=1 print("Upper case count in the file is",upper_count) print("Lower case count in the file is",lower_count) print("Digit count in the file is",digit_count) print("Space_count in the file is",space_count)...

  • PYTHON, write a function that accepts a text file's name and returns a. the number of...

    PYTHON, write a function that accepts a text file's name and returns a. the number of uppercase letters in the file b. the number of lowercase letters in the file c. the number digits in file d. the number of whitespace characters in the file

  • You're to write a C++ program that analyzes the contents of an external file called data.txt....

    You're to write a C++ program that analyzes the contents of an external file called data.txt. (You can create this file yourself using nano, that produces a simple ASCII text file.) The program you write will open data.txt, look at its contents and determine the number of uppercase, lowercase, digit, punctuation and whitespace characters contained in the file so that the caller can report the results to stdout. Additionally, the function will return the total number of characters read to...

  • (Python 3) Write a program that reads the contents of a text file. The program should...

    (Python 3) Write a program that reads the contents of a text file. The program should then create a dictionary in which the keys are individual words found in the file and the values are the number of times each word appears and a list that contains the line numbers in the file where the word (the key) is found. Then the program will create another text file. The file should contain an alphabetical listing of the words that are...

  • program must be written in python and have commentary. thank you 3. File Encryption and Decryption...

    program must be written in python and have commentary. thank you 3. File Encryption and Decryption Write a program that uses a dictionary to assign "codes" to each letter of the alphabet. For example: codes-{A':'8','a' :'9', 'B' : e','b' :'#,, etc ) Using this example, the letter A would be assigned the symbol %, the letter a would be assigned the number 9, the letter B would be assigned the symbol e, and so forth. The program should open a...

  • File Encryption and Decryption chapter 9 programming exercise #3 Design and write a python program to...

    File Encryption and Decryption chapter 9 programming exercise #3 Design and write a python program to successfully complete chapter 9 programming exercise #3. File Encryption and Decryption Write a program that uses a dictionary to assign “codes” to each letter of the alphabet. For example: codes = { ‘A’ : ‘%’, ‘a’ : ‘9’, ‘B’ : ‘@’, ‘b’ : ‘#’, etc . . .} Using this example, the letter A would be assigned the symbol %, the letter a would...

  • Python 3.7 Coding assignment This Program should first tell users that this is a word analysis...

    Python 3.7 Coding assignment This Program should first tell users that this is a word analysis software. For any user-given text file, the program will read, analyze, and write each word with the line numbers where the word is found in an output file. A word may appear in multiple lines. A word shows more than once at a line, the line number will be only recorded one time. Ask a user to enter the name of a text file....

  • Python: The attached text file: https://drive.google.com/open?id=1Hcj4Ey4NbKHn5-vyF-foR3iny0aX8y1...

    Python: The attached text file: https://drive.google.com/open?id=1Hcj4Ey4NbKHn5-vyF-foR3iny0aX8y1c Unique Words Write a program that opens a specified text file and then displays the number of unique words in the text file after stripping all the white spaces, comma, and the punctuation marks and a list of all the unique words found in the file. The list should be sorted in alphabetical order. The program should handle the ‘file not found’ error. Store each word as an element of list. Be sure not...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT