program7.py This assignment requires the main function and a custom value-returning function. The value-returning function takes a list of random integers as its only argument and returns a smaller list of only the elements that end with 7. This value-returning function must use a list comprehension to create this smaller list. In the main function, code these steps in this sequence: Set random seed to 42 import random random.seed(42) create an empty list that will the hold random integers. use a loop to add 50 random integers to the list. All integers should be between 200 and 250, inclusive. Duplicates are okay. sort the list in ascending order and then use another loop to display all 50 sorted integers on one line separated by spaces.  print a slice showing list elements indexed 5 through 10, inclusive. print a second slice showing the final 5 elements in the sorted list. execute the custom function with the entire original list as its sole argument. report the number of elements in the new "sevens" list returned by the custom function. if 207 is not in the "sevens" list, add it to the start of "sevens" and report that this happened. Otherwise, report that nothing was added. if 247 is in the "sevens" list, report the index of its first occurrence. Otherwise, append 247 to the end of the list. use another loop to display all elements in "sevens" on one line separated by spaces. Finally, report the total of the "sevens" list.   See attatched image for what the output needs to be I need pseudocode and an explanation of each step so I can learn

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter16: Searching, Sorting And Vector Type
Section: Chapter Questions
Problem 1TF
icon
Related questions
Question

program7.py
This assignment requires the main function and a custom value-returning function. The value-returning function takes a list of random integers as its only argument and returns a smaller list of only the elements that end with 7. This value-returning function must use a list comprehension to create this smaller list.

In the main function, code these steps in this sequence:

  • Set random seed to 42 import random
    random.seed(42)
  • create an empty list that will the hold random integers.
  • use a loop to add 50 random integers to the list. All integers should be between 200 and 250, inclusive. Duplicates are okay.
  • sort the list in ascending order and then use another loop to display all 50 sorted integers on one line separated by spaces. 
  • print a slice showing list elements indexed 5 through 10, inclusive.
  • print a second slice showing the final 5 elements in the sorted list.
  • execute the custom function with the entire original list as its sole argument.
  • report the number of elements in the new "sevens" list returned by the custom function.
  • if 207 is not in the "sevens" list, add it to the start of "sevens" and report that this happened. Otherwise, report that nothing was added.
  • if 247 is in the "sevens" list, report the index of its first occurrence. Otherwise, append 247 to the end of the list.
  • use another loop to display all elements in "sevens" on one line separated by spaces.
  • Finally, report the total of the "sevens" list.

 

See attatched image for what the output needs to be

I need pseudocode and an explanation of each step so I can learn

Here is the complete list of 50 elements,sorted low to high...
200 200 201 203 203 203 203 204 205 207 209 210 210 211 212 213 213 213 216 217
218 218 219 220 221 221 221 222 224 224 224 225 225 226 228 229 231 234 234 237
241 244 245 246 246 247 247 248 248 250
Elements indexed 5 to 10 in the sorted list are [203, 203, 204, 205, 207, 209]
THe final 5 elements in the sorted list are [247, 247, 248, 248, 250]
Number of elements ending with 7: 5
207 was already in the "sevens" list, so nothing was added
Found 247 at index 3 in the "sevens" list, so nothing was added
Here are the elements in the "sevens" list...
207 217 237 247 247
The total of all elements in the "sevens" list is 1155
Transcribed Image Text:Here is the complete list of 50 elements,sorted low to high... 200 200 201 203 203 203 203 204 205 207 209 210 210 211 212 213 213 213 216 217 218 218 219 220 221 221 221 222 224 224 224 225 225 226 228 229 231 234 234 237 241 244 245 246 246 247 247 248 248 250 Elements indexed 5 to 10 in the sorted list are [203, 203, 204, 205, 207, 209] THe final 5 elements in the sorted list are [247, 247, 248, 248, 250] Number of elements ending with 7: 5 207 was already in the "sevens" list, so nothing was added Found 247 at index 3 in the "sevens" list, so nothing was added Here are the elements in the "sevens" list... 207 217 237 247 247 The total of all elements in the "sevens" list is 1155
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Linked List Representation
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning