Question

1. Please write the following code in Python 3. 2. Please also show all outputs. Create...

1. Please write the following code in Python 3.

2. Please also show all outputs.

Create a dictionary named letter_counts that contains each letter and the number of times it occurs in string1. Challenge: Letters should not be counted separately as upper-case and lower-case. Intead, all of them should be counted as lower-case.

string1 = "There is a tide in the affairs of men, Which taken at the flood, leads on to fortune. Omitted, all the voyage of their life is bound in shallows and in miseries. On such a full sea are we now afloat. And we must take the current when it serves, or lose our ventures."

0 0
Add a comment Improve this question Transcribed image text
Answer #1
letter_counts = dict()
string1 = "There is a tide in the affairs of men, Which taken at the flood, leads on to fortune. Omitted, all the voyage of their life is bound in shallows and in miseries. On such a full sea are we now afloat. And we must take the current when it serves, or lose our ventures."
for x in string1.lower():
    if not letter_counts.get(x):
        letter_counts[x] = 1
    else:
        letter_counts[x] += 1
print(letter_counts)

{'t': 19, 'h': 11, 'e': 29, 'r': 12, ' ': 53, 'i': 14, 's': 15, 'a': 17, 'd': 7, 'n': 15, 'f': 9, 'o': 17, 'm': 4, ',': 4, 'w': 6, 'c': 3, 'k': 2, 'l': 11, 'u': 8, '.': 4, 'v': 3, 'y': 1, 'g': 1, 'b': 1}

Add a comment
Know the answer?
Add Answer to:
1. Please write the following code in Python 3. 2. Please also show all outputs. Create...
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
  • 1. Pleae write the following code in Python 3. Also, please show all the outputs. ....

    1. Pleae write the following code in Python 3. Also, please show all the outputs. . Write a simple Rectangle class. It should do the following: Accepts length and width as parameters when creating a new instance Has a perimeter method that returns the perimeter of the rectangle Has an area method that returns the area of the rectangle Don't worry about coordinates or negative values, etc. Python provides several modules to allow you to easily extend some of the...

  • 1. Please write the following in Python 3 code. Also, write code and not psedo code....

    1. Please write the following in Python 3 code. Also, write code and not psedo code. Also, show all outputs and share your code. Question: Create one conditional so that if “Friendly” is in w, then “Friendly is here!” should be assigned to the variable wrd. If it’s not, check if “Friend” is in w. If so, the string “Friend is here!” should be assigned to the variable wrd, otherwise “No variation of friend is in here.” should be assigned...

  • 1. Please write the following code in Python 3. Also please show all output(s) and share...

    1. Please write the following code in Python 3. Also please show all output(s) and share your code. Below is a for loop that works. Underneath the for loop, rewrite the problem so that it does the same thing, but using a while loop instead of a for loop. Assign the accumulated total in the while loop code to the variable sum2. Once complete, sum2 should equal sum1. sum1 = 0 lst = [65, 78, 21, 33] for x in...

  • 1. Please write the following program in Python 3. Also, please create a UML and write...

    1. Please write the following program in Python 3. Also, please create a UML and write the test program. Please show all outputs. (The Fan class) Design a class named Fan to represent a fan. The class contains: Three constants named SLOW, MEDIUM, and FAST with the values 1, 2, and 3 to denote the fan speed. A private int data field named speed that specifies the speed of the fan. A private bool data field named on that specifies...

  • Please write code using Python. Rubric Assignment Solution Total: 100 pts Program successfully retrieves and validates...

    Please write code using Python. Rubric Assignment Solution Total: 100 pts Program successfully retrieves and validates user input 15 pts Morse Code Function Created 10 pts Function Uses Parameters to get input message 15 pts Function successfully converts passed message to Morse Code and returns the Morse Code equivalent of message 45 pts Program calls Morse Code function and outputs the result of the function (i.e. the actual Morse Code) 15 pts Main Function Requirement Part 2 MUST have a...

  • Write the code in python, if you cannot answer all the question please dont anser, thanx very much. Please gimme a scr...

    Write the code in python, if you cannot answer all the question please dont anser, thanx very much. Please gimme a screen shot for code. Write clear code with comments and follow coding convention. Comments should include your name, student number and subject code on top of your code Question 1 Create a list to store all the subject codes that you are currently doing at UOW Then use for loop to display it in a table as in the...

  • AND THE USE OF CALCULATORS SPREADSHEETS 2. PLEASE MAKE SURE TO WRITE Sttolal ANSWER EXPLANATIONS THAT...

    AND THE USE OF CALCULATORS SPREADSHEETS 2. PLEASE MAKE SURE TO WRITE Sttolal ANSWER EXPLANATIONS THAT ARE SUPPORTED BY YOUR CALCULATIONS WHEN ASKED IN A GINEN QUESTION 3. PLEASE USE EXCEL TO CALCULATE AND SHow WORKINGS. THANKS. 2 Industrial Grinders AWN 4 During the term, we had a case study, Industrial Grinders, which focused on Sunk and Opportunity Costs. 6 Please refer to the table below, which comes from data in the Industrial Grinders case Industrial Grinders 100 Steel Rings...

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