Programming Examples

Python program to generate 6 random numbers and then print their mean median and mode


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

Solution

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

CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online Exam Quiz O Level NIELIT Study material and Quiz Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Best Website and Software Company in Allahabad Website development Company in Allahabad