-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DuckDuckGo Implement "1. Feeding the masses"
- Loading branch information
Greentaily
committed
Dec 6, 2020
1 parent
712c4f2
commit c6e44a7
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)) |