In: Computer Science
(+30) Write a python program that generates four random between -50 and +50 using python’s random number generator (RNG) see the following code (modify as needed )
import random
a = 10 # FIX
b =100 # FIX
x = random.randint(a,b) # (1) returns an integer a <= x
<= b
# modify a and b according to the lab
requirement
print('random integer == ', x)
and displays
EXAMPLE OUTPUT
If the RNG generated the four integers 22 -8 17 -5 then display
import random
a = -50 # FIX
b = 50 # FIX
x=[]
for i in range(4):
x.append(random.randint(a,b))
print("The integers are ", end ="")
for i in range(4):
print(x[i], end =" ")
print()
maximum=x[0]
minimum=x[0]
count=0
gc=0
p=0
avg4=0
for i in range(4):
if(maximum<x[i]):
maximum=x[i]
if(minimum>x[i]):
minimum=x[i]
if(x[i]%2==0):
count=count+1
if(x[i]>-25 and x[i]<25):
gc=gc+1
if(x[i]>=0):
p=p+1;
avg4=avg4+x[i]
avg=(maximum+minimum)/2
print("The maximum integer is",maximum)
print("The minimum integer is",minimum)
print("The number of even integers is",count)
print("The number of odd integers is",4-count)
print("The number of integers greater than -25 but less than 25
is",gc)
print("The number of positive integers",p)
print("The number of negative integers ",4-p)
print("The average of the smallest and largest integers",avg)
print("The average of the four integers is ",avg4/4)