26.0k views
2 votes
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

User Yatiac
by
7.8k points

1 Answer

6 votes

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: {}\\Max number: {}\\Min number: {}'.format(mean_val, max_val, min_val))

Step-by-step 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.

User Diego Sevilla
by
8.3k points

No related questions found

Welcome to QAmmunity.org, where you can ask questions and receive answers from other members of our community.