Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Provide a python program which will 1 Populate an array(list) of size 25 with integers in the range -100 (negative 100) to +100 inclusive 2

Provide a python program which will

1 Populate an array(list) of size 25 with integers in the range -100 (negative 100) to +100 inclusive

2 Display the array and its length (use the len function)

3 Display the average of all the integers in the array

4 Display the number of even integers (how many)

5 Display the number of odd integers (how many)

6 Display the number of integers > 0 (how many)

7 Display the number of integers < 0 (how many)

8 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

9 Display the integers >= median (See the : operator as in sub = array[2:6] know splice )

10 Display the integers < median see the splice operator

11 Ask the user for an integer and print the number of times the integer is in the array

HINT: see the count function below

12 Display the maximum integer

13 Display the minimum integer

14 Display the array in reverse sorted order (largest to smallest) See the sort() and reverse() functions

15 Display the gcd of the largest and smallest integers using pythons gcd function (See the lesson for an example )

Please review the Course Resources tab for a tutorial on python lists

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

SAMPLE code Template ( Lab 05Template.py)

import random import math # needed for gcd array = [] # empty list a = -100 # FIX b = 100 x = random.randint(a, b ) # Return a random integer a <= x <= b. print("random integer x == ", x) j = 0 n = 25 # size of the array 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... 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction To Constraint Databases

Authors: Peter Revesz

1st Edition

1441931554, 978-1441931559

More Books

Students also viewed these Databases questions

Question

Let X Geom(p). Find the MLE of p.

Answered: 1 week ago

Question

8. Do the organizations fringe benefits reflect diversity?

Answered: 1 week ago

Question

3. Would you say that effective teamwork saved their lives?

Answered: 1 week ago