program7_1.py Solved

20.00 $

Category:
Click Category Button to View Your Next Assignment | Homework

You'll get a download link with a: zip solution files instantly, after Payment

Securely Powered by: Secure Checkout

Description

5/5 - (1 vote)

Write a program as follows. Follow instructions carefully to avoid point deductions. All statements should be in the main function:
create an empty list named nums.
use a loop to add 20 random integers, all in the range from 1-100, to nums.
print the total of all list elements.
print the highest number in the list.
print the lowest number in the list.
sort the list and then reverse it.
use another loop to display the sorted numbers in descending order, all on the same line, separated by a single space.
determine if 75 is in the list. If it is, report the index of its first occurrence. If it is absent from the list, indicate that, too.
make a new list named middle_10 by slicing out the middle 10 elements of the descending list. Use a loop to display the elements in middle_10 all on one line.
make an empty list named evens and another empty list named odds.
use a loop to process nums, adding even elements and odd elements to their respective lists.
print both evens and odds. Crude dumps inside [ ] as shown next are okay.
Sample Output 1
List total: 712
Highest number: 85
Lowest number: 2
All list elements in descending order
85 83 67 67 58 53 50 49 30 28 23 21 20 20 16 15 14 8 3 2
75 not in the list
Middle 10 after descending sort: 53 50 49 30 28 23 21 20 20 16
Even #s [58, 50, 30, 28, 20, 20, 16, 14, 8, 2]
Odd #s [85, 83, 67, 67, 53, 49, 23, 21, 15, 3]
Sample Output 2
List total: 1000
Highest number: 99
Lowest number: 2
All list elements in descending order
99 98 87 85 78 75 72 71 54 48 47 35 31 29 25 20 18 16 10 2
First found 75 at index 5
Middle 10 after descending sort: 75 72 71 54 48 47 35 31 29 25
Even #s [98, 78, 72, 54, 48, 20, 18, 16, 10, 2]
Odd #s [99, 87, 85, 75, 71, 47, 35, 31, 29, 25]

  • program7_1.zip