MulaiMulai sekarang secara gratis

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.

Latihan ini adalah bagian dari kursus

Financial Forecasting in Python

Lihat Kursus

Petunjuk latihan

  • 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.

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# 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 dan Jalankan Kode