Get startedGet started for free

Weighted probability

Txs Tools, a company selling hardware tools, is looking to expand out of their home market A into Market B. They have done some market research, and have received the following numeric probabilities:

Sales Level (USD) Probability (%)
0 5
200 10
300 40
500 20
800 25

Txs Tools will only be motivated to expand if they can have reasonable assurance that they will achieve sales of 400 or more. To manage the different forecast sales probabilities, Txs Tools have asked you to calculate the weighted probability.

This exercise is part of the course

Financial Forecasting in Python

View Course

Exercise instructions

  • Calculate weighted probability for the sales level of Txs tools based on the probability table by creating a combined sales_probability list with pair values as a string separated by a pipe character |.
  • Create a loop iterating over the list to give the a weighted probability.
    • The for loop should iterate through each pair in the list and split the parts by specifying the character that separates the pairs.
  • Print the result.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Create the combined list for sales and probability
sales_probability = ['0|0.05', ____, ____, ____, ____] 
weighted_probability = 0

# Create a for loop to calculate the weighted probability
for ____ in sales_probability:
    parts = pair.____('____')
    weighted_probability += ____(parts[0]) * ____(parts[1])

# Print the weighted probability result
print("The weighted probability is {}.".format(____))
Edit and Run Code