From c6e44a7cacb2d2fd447c56a1ad1ac5a13e9b3a2e Mon Sep 17 00:00:00 2001 From: Greentaily Date: Sun, 6 Dec 2020 19:53:36 +0300 Subject: [PATCH] DuckDuckGo Implement "1. Feeding the masses" --- DuckDuckGo/feeding_the_masses.py | 39 ++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 DuckDuckGo/feeding_the_masses.py diff --git a/DuckDuckGo/feeding_the_masses.py b/DuckDuckGo/feeding_the_masses.py new file mode 100644 index 0000000..6dc0b89 --- /dev/null +++ b/DuckDuckGo/feeding_the_masses.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python +import sys +from math import ceil + + +def calculate(ducks, bread_nutritiousness, bread_price): + loafs = ceil(ducks / bread_nutritiousness) + money_required = loafs * bread_price + return money_required + +def main(argv): + while True: + try: + ducks = int(input("How many ducks? ")) + bread_nutritiousness = float(input("A single loaf feeds this many ducks: ")) + bread_price = float(input("Bread price per loaf: ")) + except ValueError: + print("Come again?") + continue + else: + if ducks <= 0: + print("Ducks too ephemeral to feed on bread!") + return 1 + elif bread_nutritiousness <=0: + print("Bread is devouring ducks!") + return 2 + elif bread_price <= 0: + print("Have you invested into bread futures?") + return 3 + else: + money_required = calculate(ducks, + bread_nutritiousness, + bread_price) + print("--------------") + print("Money to spend: ", money_required) + return 0 + +if __name__ == '__main__': + sys.exit(main(sys.argv)) \ No newline at end of file