Initial commit
This commit is contained in:
commit
5a9f1b1083
1 changed files with 76 additions and 0 deletions
76
simprizza.py
Executable file
76
simprizza.py
Executable file
|
@ -0,0 +1,76 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
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 {reduction_percentage:.0%} reduction")
|
||||||
|
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) > 1e-9:
|
||||||
|
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()
|
Loading…
Reference in a new issue