Esempio n. 1
0
    def base():
        cprint.info(_("Please wait a moment."))
        from modules.pythonradix import Converter
        cprint.info(
            _("Please enter the original base.\n\
HINT: Base 2 is binary, base 8 is octal, base 10 is decimal (normal), and base 16 is hex."
              ))
        originalBase = int(input(_("Enter your choice: ")))
        cprint.info(
            _("Please enter the destination base.\n\
Again, base 2 is binary, 8 is octal, 10 is normal, and 16 is hex."))
        destinationBase = int(input(_("Enter your choice: ")))
        cprint.ok(_("Please wait a moment."), end="")
        converter = Converter(originalBase, destinationBase)
        number = input(
            _("\rPlease enter your original number - it should not have a decimal point. "
              ))
        try:
            result = converter.convert(number)
        except Exception as ename:
            cprint.err(
                _("Your number was messed up, or maybe Palc screwed it up, or maybe python-radix is buggy.\nMake sure that you didn't include things like `0b' for"
                  "binary calculation. So instead of `0b100111' being your input, try `100111' instead."
                  ))
            logging.info("ERROR during base conversion! %s" % ename)
            return
        cprint.info(_("The result is... %s") % result)
        logging.info(
            "Base conversion done, with origin base %s, des base %s, and origin number %s"
            % (originalBase, destinationBase, number))
Esempio n. 2
0
 def showUserWhatIThink(whatDOyouthink):
     cprint.ok(_("I think you want me to: \n%s") % whatDOyouthink)
     isItCorrect = input(_("Is this correct? (Y/n)")).lower()
     if _("y") in isItCorrect:
         logging.info(
             "Palc chose the right calculation (%s) for calc choice that should be shown above."
             % whatDOyouthink)
     elif "n" in isItCorrect:
         cprint.info(
             _("Try different wording. Or, if you want that calculation choice to be made right, file a ticket."
               ))
         if _("y") in input(
                 _("Would you like to file a ticket? (Y/n)\nType: ")).lower(
                 ):
             import webbrowser
             webbrowser.open(
                 "http://github.com/thetechrobo/python-text-calculator/issues/new"
             )
             logging.info(
                 "User chose to file a ticket because they didn't want Palc to %s"
                 % whatDOyouthink)
             input(_("Press ENTER to continue..."))
             cprint.info(
                 _("Proceeding with the function I thought it was."))
         else:
             cprint.info(
                 _("OK, proceeding with the function I thought it was."))
     else:
         cprint.info(_("Defaulting to yes."))
         logging.info(
             "Defaulting to yes for right calc (%s) for calc choice that should be shown above"
             % whatDOyouthink)
Esempio n. 3
0
 def fib():
     hi = input(
         _("Would you like...\n    1 - Calculate a fixed amount of fibonacci numbers.\n    2 - Calculate fibonacci indefinitely.\nType: "
           ))
     if hi[0] == "1":
         cprint.info(_("Fixed it is."))
         from mathmod.fibonacci import CalculateFixedFibo
         amount = int(
             input(
                 _("How many numbers of fibonacci would you like to calculate? "
                   )))
         logging.info("About to run fixed fibonacci (amount=%s)" % amount)
         finalProduct = CalculateFixedFibo(amount)
         cprint.info(_("Your fibonacci numbers were..."))
         cprint.ok(finalProduct)
         logging.info(
             "User did fixed fibo with amount of %s, and the results are in the next log entry!..."
             % amount)
         logging.info(finalProduct)
     else:
         cprint.info(_("Looped it is."))
         from mathmod.fibonacci import CalculateLoopedFibo
         logging.info("About to run looped fibonacci")
         cprint.ok(_("Press Control-C to stop."))
         try:
             CalculateLoopedFibo()
         except Exception as ename:
             logging.err("Exception %s in looped fibonacci" % ename)
             cprint.err(_("An error occured."))
         except KeyboardInterrupt:
             logging.info("Exited fibonacci loop.")
     logging.info("User ran fibonacci function")
Esempio n. 4
0
 def spinner():
     choices = input(
         _("Please enter your choices separated by commas. Example: First part of spinner, SecondPartOfSpinner, 3, 4, 5, 6, The End\nType: "
           )).strip().split(
               ", ")  #https://www.w3schools.com/python/ref_string_split.asp
     times = int(input(_("How many times to conduct the spinner? ")))
     output = mathmod.Misc.Spinner(times, choices)
     cprint.ok(_("Your results were...\n%s") % output)
     logging.info("Spinner: choices %s, times %s, output %s" %
                  (choices, times, output))
Esempio n. 5
0
 def logarithm(
 ):  #https://stackoverflow.com/questions/33754670/calculate-logarithm-in-python
     base = input(_("1 - Base 10\n2 - Natural (e) logarithm\nPick one: "))
     number = float(input(_("What is the number? ")))
     if base[0] == "1":
         result = mathmod.Misc.log(number, False)
         cprint.info(_("The result is... %s") % result)
         doNotLog = False
     elif base[0] == "2":
         result = mathmod.Misc.log(number, True)
         cprint.info(_("The result is... %s") % result)
         doNotLog = False
     else:
         cprint.err(_("The logarithm you typed is not available."))
         cprint.ok(_("Try again."))
         logging.info(
             "User attempted to use a logarithm that is unavailable.")
         doNotLog = True
     if doNotLog:
         return
     logging.info(
         "User used logarithm choice %s with number %s, getting a result of %s"
         % (base, number, result))
Esempio n. 6
0
def palc():
    if sys.stdin.isatty(
    ):  #https://stackoverflow.com/questions/13442574/how-do-i-determine-if-sys-stdin-is-redirected-from-a-file-vs-piped-from-another
        pressanykey(_("Press any key to continue..."))
        clearScreen()
    else:
        time.sleep(1)
#CALCULATION CHOICE
    calc = input(
        _("What calculation do you wish to do? (Type `?' for a list of commands)\nType: "
          ))
    logging.info("Got calc choice %s" % calc)
    calc = calc.lower()  #make variable "calc" lowercase
    #HELP
    if "?" in calc or _("help") in calc:
        logging.info("User needed help")
        misc.h()
#TAX
    elif _("tax") in calc:
        misc.showUserWhatIThink(_("calculate tax"))
        Tax.taxCalc()
#SQUARE
    elif _("sq") in calc or "[]" in calc:
        misc.showUserWhatIThink(_("square a number"))
        n = int(input(_("Number to square? ")))
        cprint.info(n * n)
        logging.info("User squared number %s got result %s" % (n, (n * n)))
#DIVISION
    elif "/" in calc or _("div") in calc:
        misc.showUserWhatIThink(_("divide a number"))
        theBasics.division()
#SUBTRACTION
    elif "-" in calc or _("sub") in calc or _("min") in calc:
        misc.showUserWhatIThink(_("subtract a number from a number"))
        theBasics.subtraction()
#ADDITION
    elif "+" in calc or _("add") in calc or _("plus") in calc:
        misc.showUserWhatIThink(_("add two numbers"))
        theBasics.addition()
    elif lCode == "fr":
        if "ajoute" in calc:
            misc.showUserWhatIThink(_("add two numbers"))
            theBasics.addition()
#MODULO
    elif "%" in calc:
        print(
            _("1 - Find the remainder of two numbers after division\n\
2 - Use the percentage calculator.\n\
Anything else - Back to menu."))
        pOrMod = input(_("Type: "))
        if pOrMod == "1":
            theBasics.mod()
        elif pOrMod == "2":
            Percentage.chooseOneTwo()
        else:
            cprint.info(_("going back."))
            logging.info("going back. (%s)" % pOrMod)
    elif _("mod") in calc:
        misc.showUserWhatIThink(
            _("find the remainder of two numbers after division"))
        theBasics.mod()
#AREA
    elif _("area") in calc or "#" in calc:
        misc.showUserWhatIThink(_("calculate area"))
        misc.area()
#VOLUME
    elif _("vol") in calc:
        misc.showUserWhatIThink(_("use the volume calculator"))
        misc.vol()
#CUBE
    elif "{}" in calc or _("cube") in calc:
        misc.showUserWhatIThink(_("cube a number"))
        cubedNumber = int(input(_("\nType the number to be cubed: ")))
        print()
        cprint.info(cubedNumber**3)  #Manually cube number
        logging.info("User cubed number %s got result %s" % (cubedNumber,
                                                             (cubedNumber**3)))
        print()
#SPINNER
    elif _("spin") in calc or _("spinner") in calc or _("roulette") in calc:
        misc.showUserWhatIThink(_("spin a spinner"))
        misc.spinner()
#EXIT
    elif _("quit") in calc or _("exit") in calc:
        misc.showUserWhatIThink(_("quit"))
        logging.info("User exited using `quit' command")
        e()
#EXPONENTS
    elif _("power") in calc or _("ex") in calc:
        misc.showUserWhatIThink(_("use the exponent function"))
        rootsAndTheOtherOne.powerful()
    elif "^" in calc:  #IDEA SOURCE: 3N4N's (first) Pull Request on the original repo
        misc.showUserWhatIThink(_("use the exponent function"))
        rootsAndTheOtherOne.powerful()
#MULTIPLICATION
    elif "*" in calc or "x" in calc or _("multi") in calc:
        misc.showUserWhatIThink(_("multiply a number"))
        theBasics.multiplication()
#CUBE TWICE
    elif "{2}" in calc:
        cprint.err(
            _("The \"cube twice\" feature was discontinued as it was pointless. Sorry for the inconvenience."
              ))
        logging.error(
            "User attempted to use cube twice function but it's gone")
#ROOTS
    elif _("root") in calc:
        misc.showUserWhatIThink(
            _("use the root function (opposite of exponents)"))
        root = input(
            _("Square root or cube root? (square/cube)\nType: ")).lower()
        if _("square") in root:
            rootsAndTheOtherOne.sqroot()
        elif _("cube") in root:
            rootsAndTheOtherOne.curoot()
        else:
            cprint.err(
                _("Currently I don't support the root you chose. Hopefully this will change :D"
                  ))
            logging.error("User used non-existent root (%s)" % root)
#NUMBER SYSTEMS
    elif _("base") in calc:
        misc.showUserWhatIThink(_("convert number systems"))
        misc.base()
#ORD
    elif _("ord") in calc:
        misc.showUserWhatIThink(_("ord a character"))
        result = str(ord(input(_("Type in the character to ord: "))))
        logging.info("User ord'ed to get result %s" % result)
        cprint.info(_("The result is: \n%s" % result))
#LOGARITHM
    elif _("log") in calc:
        misc.showUserWhatIThink(_("use the logarithm function"))
        misc.logarithm()
#MEMORY
    elif _("mem") in calc:
        misc.showUserWhatIThink(_("use the memory function"))
        memOrRecall = input(
            _("Would you like to set the memory or recall? (set / recall)\nType: "
              ))
        if _("set") in memOrRecall.lower():
            misc.remember()
        elif _("recall") in memOrRecall.lower():
            misc.readMyMemory()
        else:
            cprint.err(_("You did not type an answer.\nAbort."))
            logging.error(
                "User didn't type an answer in MEM function (typed %s)" %
                memOrRecall)
#FIBONACCI
    elif _("fib") in calc:
        misc.showUserWhatIThink(_("use the fibonacci calculator"))
        cprint.ok(_("Starting fibonacci sequence. Please wait."))
        misc.fib()
#PERCENTAGE
    elif _("percent"
           ) in calc:  #SOURCE: https://stackoverflow.com/a/5998010/9654083
        misc.showUserWhatIThink(_("use the percentage function"))
        Percentage.chooseOneTwo()
#INTEREST
    elif _("interest") in calc:
        misc.showUserWhatIThink(_("use the interest calculator"))
        misc.calculateInterest()
#TEMPERATURE
    elif _("temperature") in calc:
        misc.showUserWhatIThink(_("use the temperature converter"))
        Temperature.tempCalc()
#CONVERSIONS
    elif _("conver") in calc:
        logging.info("use the converter functions")
        misc.showUserWhatIThink(_("use the converter functions"))
        conversion = int(
            input(
                _("1 - Convert temperature units\n2 - Convert bits and bytes and kilobytes and mebibytes and stuff\nType: "
                  )))
        if conversion == 1:
            Temperature.tempCalc()
        else:
            cprint.err(_("Not developed yet, but maybe soon! :D"))
            logging.info(
                "User typed %s into conver functions but Non Existent." %
                conversion)
#OLD
    elif "raise" in calc:
        cprint.info(
            _("This feature has been disabled due to security reasons."))
#EASTER EGG!
    elif "=" in calc:
        misc.showUserWhatIThink(_("use the e a s t e r e g g"))
        number = int(input(_("\nType in a number: ")))
        if number == 42:
            cprint.info(
                _("=42 -- the answer to life, the universe, and everything"))
            logging.info("User got the easter egg")
        else:
            cprint.info(_("Calculating..."))
            time.sleep(3)
            cprint.err(_("ERROR: Too big of a number, timed out!"))
            logging.info("User used the `=' feature for number %s" % number)


#OTHERWISE
    elif calc == "":
        logging.error("User attempted to type nothing as a command")
        cprint.err(_("I can't heeeeaaaarrrrrr yooooouuuuuuuu"))
    elif calc == " ":
        logging.error("user said nothing")
        cprint.err(_("You speak quietly"))
    else:
        logging.error("User typed an invalid command (%s)" % calc)
        cprint.err(
            _("\n"
              "I don't understand your request. Here are the currently supported calculations:\n"
              "%s\n"
              "Sorry for the inconvenience\n") % misc.hText)
Esempio n. 7
0
        ignore = input("Ignore? (Y/n): ").lower()
        if ignore[0] == "n":
            cprint.fatal("Abort.", interrupt=True)
        else:  #if user chooses to ignore
            cprint.info("Defaulting to YES.")
            logging.info("User ignored error!")

            def _(
                theEnglishString
            ):  #define a function that does nothing except give the value back so that NameErrors dont occur
                return theEnglishString
    else:
        e(1)
else:
    ignore = "undefined"
cprint.ok("Loading Palc files...\n")
lang_translations.install()
_ = lang_translations.gettext  #if both of these fail we're screwed anyway, and im NOT adding the ignoring support here
#import func and parsefunc
logging.info("Attempting to import parsefunc.py..")
try:
    from parsefunc import *
except Exception as e:
    logging.critical("Could not access file parsefunc.py (%s)" % e)
    cprint.fatal(_(
        "I can't load the file parsefunc.py. This file is necessary for proper function of the Software."
    ),
                 interrupt=True)
try:
    if ignore[0] == "y":
        from parsefunc import main
Esempio n. 8
0
 def VolMain():
     cprint.info(_(Volume.selectionMessage))
     while True:
         try:
             choice = int(input(_("Please type one: ")))
         except (ValueError, TypeError) as ename:
             cprint.err("Please type an integer")
             logging.error(
                 "User did a ValueError or TypeError while inputting choice in volinteractive (%s)"
                 % ename)
         if choice == Volume.choices.EVIL:
             cprint.ok("Sorry, that was not an option. >:)")
             logging.info(">:) choice 7")
             volume = "NULL"
         elif choice == Volume.choices.CUBE:
             from mathmod.volume import vol_cube
             a = float(input(_("What length is the side of the cube? ")))
             volume = vol_cube(a)
             logging.info("User ran Cuvolu(m) a=%s answer=%s" % (a, volume))
         elif choice == Volume.choices.CUBOID:
             from mathmod.volume import vol_cuboid
             b = float(
                 input(_("What length is the breadth of the cuboid? ")))
             h = float(input(
                 _("What length is the height of the cuboid? ")))
             l = float(input(_("What length is the cuboid? ")))
             volume = vol_cuboid(b=b, h=h, l=l)
             logging.info(
                 "User ran Cuboid Volume l=%s b=%s h=%s answer=%s" %
                 (l, b, h, volume))
         elif choice == Volume.choices.CYLINDER:
             from mathmod.volume import vol_cylinder
             r = float(input(_("What is the radius of the cylinder? ")))
             h = float(input(_("What is the height of the cylinder? ")))
             volume = vol_cylinder(r=r, h=h)
             logging.info("User ran Cylinder Volume r=%s h=%s answer=%s" %
                          (r, h, volume))
         elif choice == Volume.choices.HOLLOW_CYLINDER:
             from mathmod.volume import vol_hollow_cylinder
             ro = float(input(
                 _("What is the radius of the hollow space? ")))
             rs = float(input(_("What is the radius of the cylinder? ")))
             h = float(input(_("What is the height of the cylinder? ")))
             volume = vol_hollow_cylinder(ro=ro, rs=rs, h=h)
             logging.info(
                 "User ran Hollowcylinder Volume ro=%s rs=%s h=%s answer=%s"
                 % (ro, rs, h, volume))
         elif choice == Volume.choices.CONE:
             from mathmod.volume import vol_cone
             r = float(input(_("What is the radius of the cone? ")))
             h = float(input(_("What is the height of the cone? ")))
             volume = vol_cone(r=r, h=h)
             logging.info("User ran Conevol r=%s h=%s answer=%s" %
                          (r, h, volume))
         elif choice == Volume.choices.SPHERE:
             from mathmod.volume import vol_sphere
             r = float(input(_("What is the radius of the sphere? ")))
             volume = vol_sphere(r)
             logging.info("User ran sphere Volume r=%s answer=%s" %
                          (r, volume))
         elif choice == Volume.choices.HOLLOW_SPHERE:
             from mathmod.volume import vol_hollow_sphere
             ro = float(input(_("What is the radius of the sphere? ")))
             rs = float(input(
                 _("What is the radius of the hollow space? ")))
             volume = vol_hollow_sphere(ro=ro, rs=rs)
             logging.info(
                 "User ran Hollowsphere Volume ro=%s rs=%s answer=%s" %
                 (ro, rs, volume))
         elif choice == Volume.choices.TRIANGULAR_PRISM:
             from mathmod.volume import vol_tri_prism
             a = float(
                 input(_("What is the length of the side of the base? ")))
             h = float(input(_("What is the height of the prism? ")))
             volume = vol_tri_prism(a=a, h=h)
             logging.info(
                 "User ran Triangle Prism Volume a=%s h=%s answer=%s" %
                 (a, h, volume))
         elif choice == Volume.choices.PENTAGONAL_PRISM:
             from mathmod.volume import vol_penta_prism
             a = float(
                 input(_("What is the length of the side of the base? ")))
             h = float(input(_("What is the height of the prism? ")))
             volume = vol_penta_prism(a=a, h=h)
             logging.info("User ran PentaPrism Volume a=%s h=%s answer=%s" %
                          (a, h, volume))
         elif choice == Volume.choices.HEXAGONAL_PRISM:
             from mathmod.volume import vol_hexa_prism
             a = float(
                 input(
                     _("What is the length of the side of the hexagon? ")))
             h = float(input(_("What is the height of the prism? ")))
             volume = vol_hexa_prism(a=a, h=h)
             logging.info(
                 "User ran Hexagon Prism Volume a=%s h=%s answer=%s" %
                 (a, h, volume))
         elif choice == Volume.choices.SQUARE_BASED_PYRAMID:
             from mathmod.volume import vol_sqr_pyramid
             a = float(
                 input(_("What is the length of the side of the base? ")))
             h = float(input(_("What is the height of the pyramid? ")))
             volume = vol_sqr_pyramid(a=a, h=h)
             logging.info(
                 "User ran Square Pyramid Volume a=%s h=%s answer=%s" %
                 (a, h, volume))
         elif choice == Volume.choices.TRIANGULAR_PYRAMID:
             from mathmod.volume import vol_tri_pyramid
             a = float(
                 input(_("What is the length of the side of the base? ")))
             h = float(input(_("What is the height of the pyramid? ")))
             volume = vol_tri_pyramid(a=a, h=h)
             logging.info(
                 "User ran Triangle Pyramid Volume a=%s h=%s answer=%s" %
                 (a, h, volume))
         elif choice == Volume.choices.PENTAGON_BASED_PYRAMID:
             from mathmod.volume import vol_penta_pyramid
             a = float(
                 input(_("What is the length of the side of the base? ")))
             h = float(input(_("What is the height of the pyramid? ")))
             volume = vol_penta_pyramid(a=a, h=h)
             logging.info(
                 "User ran Pentapyramid Volume a=%s h=%s answer=%s" %
                 (a, h, volume))
         elif choice == Volume.choices.HEXAGON_BASED_PYRAMID:
             from mathmod.volume import vol_hexa_pyramid
             a = float(
                 input(_("What is the length of the side of the base? ")))
             h = float(input(_("What is the height of the pyramid? ")))
             volume = vol_hexa_pyramid(a=a, h=h)
             logging.info(
                 "User ran Hexapyramid Volume a=%s h=%s answer=%s" %
                 (a, h, volume))
         if choice in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]:
             cprint.info(_("The volume is: %s") % volume)
             break