Question: (+35) Provide a python program which will Populate an array(list) of size 25 with integers in the range -10 (negative 10) --- 10 inclusive Display

(+35) Provide a python program which will

Populate an array(list) of size 25 with integers in the range -10 (negative 10) --- 10 inclusive Display the array and its length (use the len function) Display the average of all the integers in the array Display the number of even integers (how many) Display the number of odd integers (how many) Display the number of integers > 0 (how many) Display the number of integers < 0 (how many) Display the median.

NOTE In sorted order, the median equals the 13th == array[12] element in the array. Please do not use array[12] to display the median instead consider n/2 or n//2 or a ceil or floor functions etc. That is the median should be calculated using n

Display the integers >= median (See the : operator as in sub = array[2:6] know splice ) Display the integers < median see the splice operator Ask the user for an integer and print the number of times the integer is in the array

HINT: see the count function below

Display the maximum integer Display the minimum integer Display the array in reverse sorted order (largest to smallest) See the sort() and reverse() functions Please review the Course Resources tab for a tutorial on lists and Python

Copy of the python code below is in our Source Code tab Lab 05 Template.py

SAMPLE code Template ( Lab 05 Template.py)

import random array = [] # empty list a = -10 b = 5 x = random.randint(a, b ) # Return a random integer a <= x <= b. print("random integer x == ", x) j = 0 n = 10 # (1) should be 50 while (j < n): # populate the array using the while loop x = random.randint(a, b ) # Return a random integer a <= x <= b. array.append(x) #APPEND adds to a list j = j + 1 print("array == ",array) # (2) now print the array sub = [] # subsequence sub = array[2:6] # create a subsequence start at 2 end at 5 print ('sub ', sub) # (3) # now sum sum = 0 # (4) sum for k in array: sum = sum + k print("sum == ", sum) print(array) # print array and its length print("array length is ", len(array)) array.sort() # sort array print("now sorted...") print(array) array.reverse() # reverse the array print("now sorted in reverse order...") print(array) print(" the first integer is ", array[0], " and the last integer...", array[len(array) -1]) odd = 0 # need a loop here... #FIX print('the number of odd integers is ', odd ) s = 5 # search for an integer s using count() function print("Is ", s, " in the array? ", array.count(s))

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!