Есть ли способ сказать пользователю, сколько монет ему нужно добавить или удалить в зависимости от веса мешка, который он ввел?
if coinType == "1 pence": coinWeight = 3.56 bagWeight = 356 numberCoins = 100 elif coinType == "2 pence": coinWeight = 7.12 bagWeight = 356 numberCoins = 50 elif coinType == "5 pence": coinWeight = 3.25 bagWeight = 325 numberCoins = 100 elif coinType == "10 pence": coinWeight = 6.50 bagWeight = 325 numberCoins = 50 elif coinType == "20 pence": coinWeight = 5.00 bagWeight = 250 numberCoins = 50 elif coinType == "50 pence": coinWeight = 8.00 bagWeight = 160 numberCoins = 20 elif coinType == "2 pound": coinWeight = 8.75 bagWeight = 175 numberCoins = 20 else: coinWeight = 12.00 bagWeight = 120 numberCoins = 10 weight = float(input("What is the weight of the coin bag?: ")) if weight == bagWeight: print("That is a valid coin bag weight!") print("ThankYou!") correct = "Y/n" coinCount2 = True else: print("That is an invalild weight!")
Это код, который является накоплением к той части программы, которая должна сказать пользователю, сколько монет он должен добавить или удалить.
Что я уже пробовал:
if weight < bagWeight: add = bagWeight - weight coins = add / numberCoins print("You need to add ",coins,"coins to the bag") elif weight > bagWeight: add = bagWeight - weight coins = add / numberCoins print("You need to remove ",coins,"coins to the bag!") else: exit()