Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Provide a python program which will 1 Populate an array(list) of size 25 with in

ID: 3903770 • Letter: P

Question

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 python’s 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)

Explanation / Answer

import random
import math

n = int(input("Enter number of elements:"))
list = []
for i in range(n):
    list.append(random.randint(-100,100))
print("list:")
print(list)
print("Length:",len(list))
even = 0
odd = 0
positive = 0
negative = 0

max = 0;
min = 1000
for i in range(n):
    if list[i] % 2 == 0:
       even = even + 1
    else:
       odd = odd + 1
    if list[i] < 0:
       negative = negative + 1
    else:
       positive = positive + 1
    if list[i] < min:
       min = list[i]
    if list[i] > max:
       max = list[i]


print("Number of even integers:",even)
print("Number of odd integers:",odd)
list.sort()
ind = math.ceil(n/2.0)
print("Median:",list[ind])
print("Integers less than median")
print(list[0:ind])
print("Integers more than median")
print(list[ind+1:len(list)])
print("Maximum:",max)
print("Minimum:",min)
list.reverse()
print("List in reverse order:")
print(list)
d = math.gcd(max,min)
printf("GCD of",max, "and",min, "is",d)
n1 = int(input("Enter the number whose frequence is needed:"))
count1 = 0
for i in range(n):
    if list[i] == n1:
       count1 = count1 + 1
print("Frequency of",n1, "is",count1)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote