Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Note : Create a Python module called LoopsLab to illustrate the solutions to the following problems . Each problem may or may not build on

image text in transcribedimage text in transcribedimage text in transcribed
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 . 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 strings List 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 . 0 The check for the string ' EXIT ' should not be case sensitive . . Output the strings List variable to the screen 2 . Create an empty dictionary object called strings Dictionary . Write Python code that will iterate through the string values in the strings List 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 strings Dictionary variable to the screen 3 . Write Python code that will iterate through the strings Dictionary 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 sumstr Values . At each iteration of the for loop , use another for loop to iterate though the strings List 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 strings List variable to the screen4 . Write Python code that will iterate through the strings List 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 strings List with the computed sum of the decimal values as a string . Output the strings List variable to the screen 5 . Create an empty dictionary object called reversed strings Dictionary Write Python code that will iterate through the strings Dictionary 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 ( ' str ' :37 as the dictionary , the end result would be ('rts' : 3] and store the reversed key with the same value into the reversed Strings Dictionary ." Clear the original strings Dictionary and update it with the data from the reversed Strings Dictionary 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 strings Dictionary variable to the screen 6 . Create an empty list object called remainderList . Write Python code that will iterate through the strings Dictionary 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 strings List 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 string List object Output the strings List variable to the screenExample 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 : EXIT stringsList : [' Introduction' ,` . " to' , ' Python ' , ' Programming ' ] PROBLEM ? The average string length is 7 . 75 strings Dictionary : (' Introduction " : 12 , ' Python' : 6, ' Programming ' : 11 , ' to' : 21 PROBLEM 3 The sum OF the values in the dictionary is 31 strings List : [' Introduction1 ?' , ' to?' , ' PythonE ' , ' Programming 1 1 ' ] PROBLEM 4 strings List : [ ' 13 81' , '27 7' , '695' , ' 1253 ' ] PROBLEM 5 string s Dictionary : I'mohtye " : 6 , ' ot' : 2 , ' grimmargore ' : 11 , ' noitcudortiz ' : 121 PROBLEM 6 strings List : [ ' 1381 ' !` 1277' , '696' , '1253 ' , ' 10' , '5' , ' 10' , '0 ' ]

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Programming questions