KnowledgeBoat Logo

Computer Science

Write a program to generate 6 random numbers and then print their mean, median and mode.

Python

Python Data Handling

23 Likes

Answer

import random
import statistics

a = random.random()
b = random.random()
c = random.random()
d = random.random()
e = random.random()
f = random.random()

print("Generated Numbers:")
print(a, b, c, d, e, f)

seq = (a, b, c, d, e, f)

mean = statistics.mean(seq)
median = statistics.median(seq)
mode = statistics.mode(seq)

print("Mean =", mean)
print("Median =", median)
print("Mode =", mode)

Output

Generated Numbers:
0.47950245404109626 0.6908539320958872 0.12445888663826654 0.13613724999684718 0.37709141355821396 0.6369609321575742
Mean = 0.40750081141464756
Median = 0.4282969337996551
Mode = 0.47950245404109626

Answered By

12 Likes


Related Questions