Answered step by step
Verified Expert Solution
Question
1 Approved Answer
OutPut should look same like this: Note: Create a Python module called LoopsLab to illustrate the solutions to the following problems. Each problem may or
OutPut should look same like this:
Note: Create a Python module called LoopsLab to illustrate the solutions to the following problems. Each problem may or may not build on the problem before it. 1. . Create an empty list object called stringsList. Write Python code using a while loop and prompt the user to input a string. Add that string to the stringsList variable and prompt the user again to input another string Check to see if the value of the string is 'EXIT', and if it is, exit out of the while loop. o The check for the string 'EXIT' should not be case sensitive. Output the stringsList variable to the screen 2. Create an empty dictionary object called stringsDictionary. Write Python code that will iterate through the string values in the stringsList variable using a while loop This script should calculate the average length of all the strings in the list and store the calculated value in a variable called avgStrLen Also, at each iteration, store the string from the list in the dictionary object as the key, and store the length of that string as an integer into the dictionary as the value. After the execution of the loop, output the computed average length of the strings stored in the list to the screen Output the stringsDictionary variable to the screen 3. Write Python code that will iterate through the stringsDictionary based on the keys in that dictionary using a for loop. This script should sum up the integer values in the dictionary and store the result in the variable sumStrValues. At each iteration of the for loop, use another for loop to iterate though the stringsList object to find the value in the list that matches the key in the dictionary. When found, append the value in the dictionary at the current iteration to the value in the list After the execution of the loop, output the computed sum of the values stored in the dictionary to the screen. Output the stringsList variable to the screen 4. Write Python code that will iterate through the stringsList using a while loop At each iteration in the list, use a for loop to iterate through each character of that string and convert it to its associated decimal value. Sum the decimal values, and replace the current string value in the stringsList with the computed sum of the decimal values as a string. Output the stringsList variable to the screen 5. Create an empty dictionary object called reversedStringsDictionary Write Python code that will iterate through the stringsDictionary based on the keys in that dictionary using a for loop. This script should reverse the key stored in the dictionary (i.e. Instead of having f'str':3) as the dictionary, the end result would be f'rts':3) and store the reversed key with the same value into the reversedStringsDictionary. Clear the original stringsDictionary and update it with the data from the reversedStringsDictionary variable The original key:value pairs should not be in the dictionary anymore. Only the key:value pairs with the reversed keys should be in the dictionary. Output the stringsDictionary variable to the screen 6 Create an empty list object called remainderList. Write Python code that will iterate through the stringsDictionary in alphabetical order based on the keys in that dictionary using a for loop. At each iteration of the for loop, use another for loop to iterate though the stringsList The for loop should sum the integer values of the strings in the stringsList After computing the sum, compute the remainder after dividing the computed sum by the current iteration's dictionary's value Append the computed remainder to the stringList object Output the stringsList variable to the screen Example Output: PROBLEM 1 Enter a string value to add to the list of strings: Introduction Enter another string value to add to the list of strings: to Enter another string value to add to the list of strings: Python Enter another string value to add to the list of strings: Programming Enter another string value to add to the list of strings: exT stringsList: ['Introduction', 'to, 'Python', 'Programming' PROBLEM 2 The average string length is 7.75 stringsDictionary: 'Introduction': 12, 'Python': 6, 'Programming': 11. 'to':2) PROBLEM 3 The sum of the values in the dictionary is 31 stringsList: ['Introduction12, 'to2", 'Python6', 'Programmingl1' ----PROBLEM 4 stringsList: '1381', '277', 696', 1253' -PROBLEM 5 stringsDictionary: 'nohtyp':6, 'ot':2,gnimmargorP: 11, 'noitcudortnI 12) PROBLEM 6 stringsList: '1381', '277' 696','1253', '10', '5', '10', 'o
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