I am trying to create a program that accepts two lists. The first list being any number, the second list being the probability of the number being output. The program will ask for input on the number and then probability. The program then merges these two so they map each other. The program should then return one number based on the probability entered.
I have created this program and it does this, I just have one question, how can I get it so that for to probability list, you can enter floats (0.1, 0.2). I can do this but then other parts of the code return errors. Also how can I get it so the probability that the user enters can only add up to 1 if floats are used (0.5, 0.5) or 10 if floats aren't used?
pos_values = []
probability = []
maxLengthList = 5
while len(pos_values) < maxLengthList:
number = input("Enter a number: ")
pos_values.append(number)
prob = input("Enter a probability: ")
probability.append(prob)
cumulative_probability = list(zip(pos_values, probability))
prob = [val for val, cnt in cumulative_probability for i in range(cnt)]
outcome = []
for i in range (1):
outcome.append(random.choice(prob))
print('Possible outcome returned is: ', outcome)
My code does exactly what i want it to, my question is how can i make so that the sum of the probabilities entered can't go over 1 or 10.