Programming Examples
Python program that generates six random numbers in a sequence created with start stop step
Write a program that generates six random numbers in a sequence created with (start, stop, step). Then print the mean, median and mode of the generated numbers.
Solution
import random
import statistics
start = int(input("Enter start: "))
stop = int(input("Enter stop: "))
step = int(input("Enter step: "))
a = random.randrange(start, stop, step)
b = random.randrange(start, stop, step)
c = random.randrange(start, stop, step)
d = random.randrange(start, stop, step)
e = random.randrange(start, stop, step)
f = random.randrange(start, stop, step)
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
Enter start: 100
Enter stop: 500
Enter step: 5
Generated Numbers:
235 255 320 475 170 325
Mean = 296.6666666666667
Median = 287.5
Mode = 235