예제 #1
0
def main():
    """
    1) Get necessary parameters from the user.
    2) Calculate the mixture.
    3) Output the results.
    """
    abv1 = decimal.Decimal(Cli.arg(*PROMPT_LIST))  # pylint: disable=star-args
    abv2 = decimal.Decimal(Cli.arg(*PROMPT_LIST))  # pylint: disable=star-args
    target_abv = decimal.Decimal(Cli.arg(*PROMPT_LIST))  # pylint: disable=star-args

    # If it is possible to create a mixture according to the provided
    # parameters,
    # find and output the answer.
    if (target_abv >= abv1 or target_abv >= abv2) and (target_abv <= abv1 or target_abv <= abv2):
        target_vol = decimal.Decimal(Cli.arg(*PROMPT_LIST))  # pylint: disable=star-args

        vol1 = target_vol * (target_abv - abv2) / (abv1 - abv2)
        vol2 = target_vol - vol1
        print("\nYou will need {:4.3} fl. oz. of the first ingredient ({}% ABV), and".format(vol1, abv1))
        print("\t      {:4.3} fl. oz. of the second ingredient ({}% ABV).\n".format(vol2, abv2))

    # Otherwise, apologize to the illogical user.
    else:
        print("Sorry, that's not possible.")  # pylint: disable=C0325
예제 #2
0
#!/usr/bin/python

import sys
from cjh.shell import Cli

# Calculate how much of 2 different solutions you need to 
#    combine to reach a target %ABV and volume.

# Use: MixTool.py $%ABV1 $%ABV2 $TARGET_%ABV $TARGET_VOLUME

# If no arguments are given, input is from stdin.  
# Pretty much a direct translation of MixTool.pl

if len(sys.argv[1:])==0 :
    abv1 = Cli.input("%ABV of first ingredient: ")

else :
    abv1 = sys.argv[1]
abv1 = float(abv1)

if len(sys.argv[1:]) < 2 : 
    abv2 = Cli.input("%ABV of second ingredient: ")

else :
    abv2 = sys.argv[2]
abv2 = float(abv2)

print('')


if len(sys.argv[1:]) < 3 :