Question
********Python********* 5. Count the characters in a string - using a dictionary Rewrite your python program from HW2 to prompt the user for a string,
********Python*********
5. Count the characters in a string - using a dictionary
Rewrite your python program from HW2 to prompt the user for a string, and count how many times each vowel (a, e, i, o, u) is repeated in a string. This time use a dictionary to track the counts, and use a loop to print the counts.
Sample input:
Sample output:
There are 0 instances of a in google. There are 1 instances of e in google. There are 0 instances of i in google. There are 2 instances of o in google. There are 0 instances of u in google.
6. Tracking inventory with a dictionary
You are going on an adventure and will take a number of objects with you. They will be represented using a dictionary and lists. Starting with the initial dictionary here, write the Python statement for each step below. Create a complete Python program with the initial dictionary and all of your steps.
You are starting with these initial items in your inventory:
inventory = {'gold': 150, 'pouch' : ['flint', 'twine', 'lucky charm'], 'backpack' : ['knife', 'bedroll', 'jerky']}
Write the code for each of the following steps:
1. Add a key for a 'pocket'.
2. Put in your 'pocket' the values 'pebble', 'large chestnut', and 'lint'.
3. Sort the items in your backpack.
4. You don't like jerky. Remove it and add some 'crackers'.
5. You found 25 gold. Add that to the 'gold' key.
6. Print the final state of the dictionary and confirm that it has the following elements (not necessarily in the same order, of course).
Output should look similar to this:
inventory = {'gold': 175,
'pouch' : ['flint', 'twine', 'lucky charm'], 'backpack' : ['bedroll', 'crackers', 'knife'], 'pocket' : ['pebble', 'large chestnut', 'lint']}
Remember because this is a dictionary your order of gold, pouch, backpack, and pocket may vary
7. Polling for America's Got Talent Winners Ultimate Challenge Contest
Write a program that simulates a poll for voting for contestants of America's Got Talent: the program should repeatedly prompt the user for a contestant name (each entry is a vote: you can pretend that each time the program prompts the user, it's a different voter). Optionally, you can determine the most popular performers and select the top 5 contestents to go head to head in America's Got Talent Ultimate Challenge Contest. Use the following steps to tally the votes and select the contestants.
1. Initialize a dictionary with the keys "Darci Lynne", "Angelica Hale", and "Angelina Green" with each having the value 0.
2. Repeatedly prompt the user for a contestant name to vote for, adding/updating the relevant key/value pair in the dictionary to tally the votes for each contestant. Stop prompting when the user enters "done".
3. After all the votes have been entered, print out all the contestants and their corresponding vote tallies.
4. Optional challenge: Compute the 5 most popular contestants and wish them congratulations by name. "Congratulations, Darci Lynne!". Do this after you have the rest of the program working and have tested your code.
Example input:
Darci Lynne Celine Tam Darci Lynne Darci Lynne .... Bello Nock Angelina Green Celine Tam Done
Output should look something like this:
Darci Lynne 34 Bello Nock 29 Oscar Hernadez 1 Celine Tam 25 Preacher Lawson 2 Brobots & Mandroidz 14 The Masqueraders 13
If you implement the optional piece:
Congratulations, Darci Lynne, you're in the Ultimate Challenge with 34 votes! Congratulations, Bello Nock, you're in the Ultimate Challenge with 29 votes! Congratulations, Celine Tam, you're in the Ultimate Challenge with 25 votes! Congratulations, Brobots & Mandroidz, you're in the Ultimate Challenge with 14 votes! Congratulations, The Masqueraders, you're in the Ultimate Challenge with 13 votes!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started