89 lines
2.4 KiB
Python
Executable File
89 lines
2.4 KiB
Python
Executable File
#!/usr/bin/env python3


# Copyright (C) 2019 Midgard


#


# This program is free software: you can redistribute it and/or modify it under the terms of the


# GNU General Public License as published by the Free Software Foundation, either version 3 of the


# License, or (at your option) any later version.


#


# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without


# even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU


# General Public License for more details.


#


# You should have received a copy of the GNU General Public License along with this program. If


# not, see <https://www.gnu.org/licenses/>.




import math






def main():


print("Reduction in cents: ", end="")


reduction = int(input())


print()




prices = []


i = 1


done = False


while not done:




if i == 1:


print(f"Price {i} in cents: ", end="")


else:


print(f"Price {i} (empty to finish): ", end="")


read = input()


if not read:


break


price = int(read)




print(f" Amount of orders at this price: ", end="")


amount = int(input())




print()




prices.append((amount, price))




i += 1




print()




print("")


print()




total_without_reduction = sum(amount * price for amount, price in prices)


total_with_reduction = total_without_reduction  reduction




reduction_percentage = reduction / total_without_reduction


reduction_prices = [


math.ceil((1  reduction_percentage) * price)


for _, price in prices


]


total_reducted_prices = sum(


amount * reduction_price


for (amount, _), reduction_price in zip(prices, reduction_prices)


)


gap = total_with_reduction  total_reducted_prices




total_items = sum(amount for amount, _ in prices)






print(f"You got a reduction of {reduction_percentage:.0%}")


print()




print(" #  Normal price  Reduction price")


print("")




for (amount, price), reduction_price in zip(prices, reduction_prices):


print(f"{amount:2d}  €{price/100:11.2f}  €{reduction_price/100:14.2f}")




print("")


print(f"{total_items:2d}  €{total_without_reduction/100:11.2f}  €{total_reducted_prices/100:14.2f}")


if abs(gap) > 1e9:


print(f" You paid €{total_with_reduction/100:14.2f}")


if gap < 0:


print(f"This solution has a bonus of {gap}¢ for the courier.")


else:


print(f"This solution leaves {gap}¢ unaccounted for.")






if __name__ == "__main__":


main()
