My function is as below. I am taking input of 2 nos, finding random nos between them and then multiplying them all.
start = int(input("Enter start value"))
end = int(input("Enter end value"))
import random
numlist = random.sample(range(start,end),10)
from functools import reduce
prod = reduce(lambda x,y: x*y, numlist)
print("the product of random nos: {0} is {1}".format(numlist,prod))
The output is as below
Enter start value7
Enter end value89
list of random nos are: [58, 13, 47, 43, 44, 56, 86, 14, 25, 71]
the product of random nos: [51, 30, 7, 25, 49, 29, 35, 54, 27, 67] is 1300840136977500
My question is a) why does the list of random nos change (first line [58,13
..second line [51,30
...) even though i haven't run this numlist = random.sample(range(start,end),10)
line of code again.
What is happening here ?
Aucun commentaire:
Enregistrer un commentaire