vendredi 16 octobre 2020

How can i produce an array of n random integers that are both positive and negative

I wanted to produce an array of n random integers that are both positive and negative. For example if i put in 4 it would produce [1,-2,-4,3]

import stdio
import sys
import random

n = int(input(sys.argv[0]))
y = n * -1

randomlist = []
for i in range(0,n):
    arr = random.randint(n, y)
    randomlist.append(arr)
print(randomlist)


sum = 0
for i in randomlist:
    sum += i

avg = sum/x
print("Average is",avg)
print("Max value is", max(randomlist))
print("Min value is", min(randomlist))





Aucun commentaire:

Enregistrer un commentaire