Computer Science
Write a program to generate 6 random numbers and then print their mean, median and mode.
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
Related Questions
Write a program to find a side of a right angled triangle whose two sides and an angle is given.
Write a program to calculate the radius of a sphere whose area (4πr2) is given.
Write a program to generate 3 random integers between 100 and 999 which is divisible by 5.
Write a program to generate 6 digit random secure OTP between 100000 to 999999.