I have designed a calculator to compute the percentage chances of winning individual items in a lottery that operates by drawing items from a set with varying prices. Currently, the results are calculated proportionally to the price of each item. However, I would like to modify the code so that the probabilities are more diverse. For instance, I would like the five last items with values ranging between $100 and $500 to have the lowest chances of being drawn, ranging between 2 and 0.01 percent, while the remaining items would maintain a proportional distribution. Could someone assist me in adjusting the code accordingly? Here is code:
def calculate_drop_chance(item_prices):
total_inverse_price = sum(1 / price for price in item_prices)
drop_chances = [(1 / price) / total_inverse_price for price in item_prices]
return drop_chances
def main():
item_prices_input = input("Enter the prices of items separated by space: ")
item_prices = [float(price) for price in item_prices_input.split()]
drop_chances = calculate_drop_chance(item_prices)
print("\nDrop chances of items:")
for i, chance in enumerate(drop_chances):
print(f"Item {i+1}: {chance * 100:.2f}%")
if __name__ == "__main__":
main()