Answered step by step
Verified Expert Solution
Question
1 Approved Answer
21. (+20) Write a python program that: Ask the user for a string and creates the following dictionary: The values are the letters in the
21. (+20) Write a python program that: Ask the user for a string and creates the following dictionary: The values are the letters in the string, with the corresponding key being the place in the string. For example if the user entered the string "csc120" then create the dictionary d a. d {0: 'C', 1: 'S', 2:'C', 3: '1', 4:'2', 5: 'O') b. c. Display the length of the dictionary d In this case it is 6 Ask the user for a key(integer). If the key is in the dictionary display the corresponding value. As an example if the user entered 2 display?if the user entered a key that was not in the dictionary display "Error key not found" Ask the user for a value (one of the characters). If the value is in the dictionary display nValue found" otherwise display Value not found". As an example if the user entered 'C' display "Value found" d. e. Ask the user for a string o digits, separated by a comma. Print out the corresponding values for those digits. For example if the user enters the string "0,1, 4" then print out?'S, 2' (or "CS2" ) At issue is how to handle out of range digits for example, in our case, any digits in the range 0.. 5 should generate a corresponding value but any digit(s) > 5 OR 0 has to handled appropriately-Ileave that to you to decide (generate an error message is a suggestion) Tutorial on sets and dictionary can be found at (left side in the Table of Contents 5.4 and 5.5 https://docs.python.org/2/tutorial/datastructures.html Tutorial on strings can be found at htt en.wikibooks.orgq/wiki/Python ramming/Stri Try your code on the string "CSC 120ComputingFundamentals" 21. (+20) Write a python program that: Ask the user for a string and creates the following dictionary: The values are the letters in the string, with the corresponding key being the place in the string. For example if the user entered the string "csc120" then create the dictionary d a. d {0: 'C', 1: 'S', 2:'C', 3: '1', 4:'2', 5: 'O') b. c. Display the length of the dictionary d In this case it is 6 Ask the user for a key(integer). If the key is in the dictionary display the corresponding value. As an example if the user entered 2 display?if the user entered a key that was not in the dictionary display "Error key not found" Ask the user for a value (one of the characters). If the value is in the dictionary display nValue found" otherwise display Value not found". As an example if the user entered 'C' display "Value found" d. e. Ask the user for a string o digits, separated by a comma. Print out the corresponding values for those digits. For example if the user enters the string "0,1, 4" then print out?'S, 2' (or "CS2" ) At issue is how to handle out of range digits for example, in our case, any digits in the range 0.. 5 should generate a corresponding value but any digit(s) > 5 OR 0 has to handled appropriately-Ileave that to you to decide (generate an error message is a suggestion) Tutorial on sets and dictionary can be found at (left side in the Table of Contents 5.4 and 5.5 https://docs.python.org/2/tutorial/datastructures.html Tutorial on strings can be found at htt en.wikibooks.orgq/wiki/Python ramming/Stri Try your code on the string "CSC 120ComputingFundamentals
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