CommencerCommencer gratuitement

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.

Cet exercice fait partie du cours

Financial Forecasting in Python

Afficher le cours

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.

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de 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(____))
Modifier et exécuter le code