program7.py This program requires the main function and a custom value-returning function. In the main function, code these steps in this sequence: use a list comprehension to generate 100 random integers all from 1 to 100, inclusive. These represent the ages of a population of 100 people. pass the list as the sole argument to the custom value-returning function. In the custom function: sort the list in descending order using methods described in Chapter 7 return the sorted list to main Back in main: Within a for loop, print a 10 by 10 representation of the ages returned by the custom function. As listed in the example output, the ages should be in descending order and evenly spaced. Also, within the same for loop accumulate the sum of all ages. Using a built-in function determine the age of the oldest person, then print it . Using a built-in function to determine the age of the youngest person, then print it . Determine the average age by making use of the sum of all ages calculated in the for loop above and a built-in function, then print the average age so that two decimal positions are included. Within a for loop,  count the minor ages less than 18  count the senior ages that are greater than 65 Print the count of minor ages and senior ages . Use either a loop or a list comprehension to create a list of college ages (ages that are greater or equal to 18 and less than or equal to 21).  Print the count of senior ages making use of a built-in function.   My code so far is: # importing random module import random # main function definition def main():     # declared empty list, arrList     arrList = []     # append 50 random numbers in arrList     # with the value ranges from 1 and 100 inclusive     for i in range(0,100):         # randomNum stores the random number between 1 and 100 inclusive         # by using random.randint(1,100) function         randomNum = random.randint(1,100)         # append randomNum to the arrList         arrList.append(randomNum)     # sort the arrList in ascending order     arrList.sort()     # print the elements of arrList in one line with spaces     print("\nElements in the list: ")     for i in range(0,len(arrList)):         # printing elements         print(arrList[i],end=" ") main()   Additonal help with explanations would be great, thank you in advance!

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

program7.py
This program requires the main function and a custom value-returning function.


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

  • use a list comprehension to generate 100 random integers all from 1 to 100, inclusive. These represent the ages of a population of 100 people.
  • pass the list as the sole argument to the custom value-returning function.

In the custom function:

  • sort the list in descending order using methods described in Chapter 7
  • return the sorted list to main

Back in main:

  • Within a for loop, print a 10 by 10 representation of the ages returned by the custom function. As listed in the example output, the ages should be in descending order and evenly spaced. Also, within the same for loop accumulate the sum of all ages.
  • Using a built-in function determine the age of the oldest person, then print it .
  • Using a built-in function to determine the age of the youngest person, then print it .
  • Determine the average age by making use of the sum of all ages calculated in the for loop above and a built-in function, then print the average age so that two decimal positions are included.
  • Within a for loop, 
    • count the minor ages less than 18 
    • count the senior ages that are greater than 65
  • Print the count of minor ages and senior ages .
  • Use either a loop or a list comprehension to create a list of college ages (ages that are greater or equal to 18 and less than or equal to 21). 
  • Print the count of senior ages making use of a built-in function.

 

My code so far is:

# importing random module
import random

# main function definition
def main():
    # declared empty list, arrList
    arrList = []

    # append 50 random numbers in arrList
    # with the value ranges from 1 and 100 inclusive
    for i in range(0,100):
        # randomNum stores the random number between 1 and 100 inclusive
        # by using random.randint(1,100) function
        randomNum = random.randint(1,100)
        # append randomNum to the arrList
        arrList.append(randomNum)

    # sort the arrList in ascending order
    arrList.sort()

    # print the elements of arrList in one line with spaces
    print("\nElements in the list: ")
    for i in range(0,len(arrList)):
        # printing elements
        print(arrList[i],end=" ")
main()

 

Additonal help with explanations would be great, thank you in advance! 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Events
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-engineering and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY