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.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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.

Sample Output

Here is the complete list of 50 elements, sorted from low to high:

200, 200, 201, 203, 203, 203, 204, 205, 207, 209, 210, 210, 211, 212, 213, 213, 216, 217, 218, 218, 219, 220, 221, 221, 222, 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 from low to high: 200, 200, 201, 203, 203, 203, 204, 205, 207, 209, 210, 210, 211, 212, 213, 213, 216, 217, 218, 218, 219, 220, 221, 221, 222, 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 2 images

Blurred answer
Knowledge Booster
Array
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
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education