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: 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 247to 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.

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter7: Arrays
Section7.5: Case Studies
Problem 3E
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:

  • 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 247to 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.

This is Python for COP 1000, I have to use def main. Thank you!

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
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