Write a program that takes a positive integer argument N, and prints out the average, minimum, and maximum (in that order) of N uniform random numbers that it generates. Note that all three statistics should be over the same sequence of N random numbers python

Respuesta :

Answer:

from random import seed, choices

from statistics import mean

number = int(input("Enter integer number: "))

if number > 0:

   try:

       data = range(number+1)

       # to generate a pseudo-random number list.

       seed(10)

       # you can also use: num_list = [random.randint(0, number+1) for i in data]

       num_list = choices(data, k=len(data))

       print(num_list)

       mean_val = round(mean(num_list), 2)

       min_val = min(num_list)

       max_val = max(num_list)

   except ValueError:

       print("Must be an integer value.")

print('Avg number: {}\nMax number: {}\nMin number: {}'.format(mean_val, max_val, min_val))

Explanation:

To generate random items in a list of integers, the random choices method is used and a sequence is passed as an argument. The average, maximum, and minimum number of the list is calculated and displayed.