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))
def powerful(): origin = input(_("Enter the original number: ")) ex = input(_("Enter the exponent: ")) try: float(origin) float(ex) except Exception as ename: cprint.err( _("ERRID 3: One or more of your numbers was not a number.")) raise ValueError( _("ERRID3: One or more of the numbers was not a number. (Dump: origin=%s, ex=%s)" ) % (origin, ex)) try: returnedNumber = mathmod.ExponentsAndRoots.exponent(origin, ex) except ValueError as ename: cprint.err(_("An exception was raised!\nValueError\n")) logging.error( "While parsing curoot(%(number)s), a ValueError was thrown. (%(error)s)" % { "number": number, "error": ename }) raise cprint.info(_("The answer is... %s") % returnedNumber) logging.info("User exponented number %s with %s, getting %s" % (origin, ex, returnedNumber))
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")
def percentage1(): origin = float(input(_("What is the ORIGINAL NUMBER? "))) percent = float(input(_("What is the PERCENTAGE? "))) logging.info("Got percentage RN origin %s percent %s" % (origin, percent)) cprint.info(_("That equals...")) try: cprint.info(mathmod.Misc.whatIsXPercentOf(percent, origin)) except ValueError: cprint.err( _("You requested an impossible situation by entering 0 there - that would require division by 0." ))
def chooseOneTwo(): chosenPercentageCalc = int( input( _('''1 - Calculate "What is x% of y?" 2 - Convert a number to percentage (i.e. how much percent of ___ is ___?). Type: '''))) if chosenPercentageCalc == 1: Percentage.percentage1() elif chosenPercentageCalc == 2: Percentage.percentage2() else: cprint.err(_("You didn't type a valid answer. Abort.")) logging.info( "User did not answer correct percentage interpretation")
def percentage2(): origin = float(input(_("What is the number that would be 100%? "))) part = float( input( _("What is the number that you want to convert to percentage (i.e. this number out of the number that would be 100%)? " ))) logging.info("Got percentage RN origin %s and %s" % (origin, part)) cprint.info(_("That equals...")) try: cprint.info(mathmod.Misc.findPercentage(part, origin)) except ValueError: cprint.err( _("You requested an impossible situation by entering 0 there - that would require division by 0." ))
def readMyMemory(): cprint.info( _("This is the remember function.\nIt will read a number that was previously stored in a file." )) try: slot = str(int(input(_("What slot number did you use? ")))) with open(slot, "r") as memory: theMem = memory.read() cprint.info(_("Number: %s" % theMem)) logging.info("Retrieved number %s from memory slot %s" % (theMem, slot)) except Exception as e: logging.info( "There was an error retrieving the file from memory. (Err %s)" % e) cprint.err( _("There was an error reading the file. Did you save the number by using the save function? Did you accidentally rename the file? " "Do you have the correct permissions?"))
def division(): nums = Builtins.getInput() try: returnedNumber = mathmod.Arithmetic.division(*nums) except ZeroDivisionError: logging.error("User decided to divide by zero. (nums: %s)" % nums) raise SyntaxError("yes, because diving by 0 makes sense") % (nums) except ValueError as ename: cprint.err(_("An exception was raised!\nValueError\n")) logging.error( "While parsing div(%(n1)s), a ValueError was thrown. (%(error)s)" % { "n1": nums, "error": ename }) raise cprint.info(_("The response is...%s") % returnedNumber) logging.info("Parsed division with %s as nums, answer as %s" % (nums, returnedNumber))
def getInput(): nums = [] num = float(input(_("Please enter the first number: "))) nums.append(num) while True: num = input( _("Please enter the next number; a blank line will confirm your numbers: " )) if num == "": break try: num = float(num) except Exception as ename: cprint.err(_("ERRID 3: %s is not a number.") % num) logging.error( "ERRID3: The number given was not a number. (Dump: %s)" % num) nums.append(num) return nums
def curoot(): try: number = float(input(_("Number to be rooted? "))) except Exception as ename: cprint.err( _("ERRID 3: One or more of your numbers was not a number.")) raise ValueError( _("ERRID3: One or more of the numbers was not a number. (Dump: n1=%s, n2=%s)" ) % (n1, n2)) try: nothernumber = mathmod.ExponentsAndRoots.cuRoot(number) except ValueError as ename: cprint.err(_("An exception was raised!\nValueError\n")) logging.error( "While parsing curoot(%(number)s), a ValueError was thrown. (%(error)s)" % { "number": number, "error": ename }) raise logging.info("Parsed curoot(%s) to get %s..." % (number, nothernumber)) cprint.info(_("The answer is... %s") % nothernumber)
def taxCalc(): cprint.info( _('''1 - Ontario Sales Tax 2 - Quebec Sales Tax 3 - Yukon, Northwest Territories, Nunavut, and Alberta Sales Tax 4 - BC / Manitoba Sales Tax 5 - New Brunswick / Nova Scotia / Newfoundland / PEI Sales Tax 6 - Saskatchewan Sales Tax 7 - Custom Tax''')) whatPlace = int(input(_("Choose one: "))) if whatPlace == 1: percent = 13.0 elif whatPlace == 2: percent = 14.975 elif whatPlace == 3: percent = 5.0 elif whatPlace == 4: percent = 12.0 elif whatPlace == 5: percent = 15.0 elif whatPlace == 6: percent = 11.0 elif whatPlace == 7: percent = float( input( _("Please enter the tax percentage without the percent sign: " ))) else: cprint.err(_("You did not type answer. Abort.")) logging.error("User typed %s into tax...aka an invalid answer." % whatPlace) return originPrice = float( input(_("What is the original price (before tax)? "))) result = mathmod.Misc.tax(originPrice, percent) logging.info( "User used Sales Tax %s Percent with originPrice %s, price %s" % (percent, originPrice, newPrice)) cprint.info(_("After tax, the price is: \n%s" % result))
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))
def tempCalc(): message = """What is the %s temperature unit? 1 - Farenheit 2 - Celsius 3 - Kelvin 4 - Rankine \033[A\033[A\033[A\033[A\033[A""" source = int(input(_(message) % "source")) origin = float(input(_("Please enter the original temperature..."))) destination = int(input(_(message % "destination"))) print(" ") try: yolo = mathmod.Misc.calculateTemperature(origin=origin, source=source, destination=destination) except ValueError: cprint.err(_("Invalid input(s).")) logging.error("User typed invalid temperature answer %s, %s" % (source, destination)) cprint.info(_("That equals... \n%s ") % yolo) logging.info( "User ran temperature calculator, with source %s, destination %s, and original number %s" % (source, destination, origin))
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)
logging.basicConfig( filename="palc.log", level=logging.DEBUG, format= '%(levelname)s @ %(asctime)s %(message)s. Logged on line %(lineno)d in function %(funcName)s, file %(filename)s.', datefmt='%d/%m/%Y %H:%M:%S' ) #set up logging, thanks for this website www.programcreek.com/python/example/136/logging.basicConfig for a few great examples! #ask for language standTextOut("Language Selection // Language", print, cprint.info) cprint.info("1 - English // Anglais\n2 - Français // French") while True: try: language = int(input("Type: ")) except ValueError as ename: logging.info("ValueError in language select (%s)" % ename) cprint.err("Invalid input // Entrée invalide") continue if language == 1: lCode = "en" break elif language == 2: lCode = "fr" break if lCode not in ["en", "fr"]: logging.fatal("USER DID NOT SPECIFY A VALID LANGUAGE!") cprint.warn( "This language doesn't exist. Did you mean...\nEnglish? // Ce language n'existe pas. Tu peut-être veux dire ...\nAnglais ? (Y/n) " ) if input()[0].lower() == "y": logging.info("Nvm, they meant English.") ignore = "n"
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
def AreaMain(): cprint.info(_(Area.selectionMessage)) while True: try: choice = int(input(_("Please type one: "))) except (ValueError, TypeError): cprint.err(_("Please type an integer")) logging.error( "User did ValueError // TypeError while inputting areaInteractive choice" ) if choice == Area.choices.EVIL: cprint.err(_("I was too lazy to change 7.")) logging.info("Lazy 7") area = "NULL" elif choice == Area.choices.EQUILATERAL_TRIANGLE: from mathmod.area import area_equilateral_triangle as equtri a = float(input( _("What length is the side of the triangle? "))) area = equtri(a) logging.info( "User used equalateral triangle area with origin %s answer %s" % (a, area)) elif choice == Area.choices.RIGHT_ANGLE_TRIANGLE: from mathmod.area import area_right_triangle as righttri b = float(input( _("What length is the base of the triangle? "))) h = float( input(_("What length is the height of the triangle? "))) area = righttri(b=b, h=h) logging.info( "User used Righttri area with variable b=%s, h=%s, answer=%s" % (b, h, area)) elif choice == Area.choices.ACUTE_TRIANGLE: from mathmod.area import area_acute_triangle as actri a = float(input(_("What is the length of the first side? "))) b = float(input(_("what is the length of the second side? "))) c = float(input(_("What is the length of the third side? "))) area = actri(a, b, c) logging.info( "User used Acutetri area with variable a=%s, b=%s, c=%s, answer=%s" % (a, b, c, area)) elif choice == Area.choices.OBTUSE_TRIANGLE: from mathmod.area import area_obtuse_triangle as obtri a = float(input(_("What is the length of the first side? "))) b = float(input(_("What is the length of the second side? "))) c = float(input(_("What is the length of the third side? "))) area = obtri(a, b, c) logging.info( "User used Obtuse Triangle area with variable a=%s, b=%s, c=%s, answer=%s" % (a, b, c, area)) elif choice == Area.choices.SQUARE: from mathmod.area import area_square as sq a = float( input(_("What is the length of the side of the square? "))) area = sq(a) logging.info( "User used Square area with variable a=%s, answer=%s" % (a, area)) elif choice == Area.choices.RECTANGLE: from mathmod.area import area_rectangle as rec l = float(input(_("What is the length of the rectangle? "))) b = float(input(_("What is the height of the rectangle? "))) area = rec(l, b) logging.info( "User used Rectangle area with variable l=%s, b=%s, answer=%s" % (l, b, area)) elif choice == Area.choices.PARALLELOGRAM: from mathmod.area import area_parallelogram as para b = float(input(_("What is the length of the base? "))) h = float(input(_("What is the height of the shape? "))) area = para(b, h) logging.info( "User used Parallelogram area with variable b=%s, h=%s, answer=%s" % (b, h, area)) elif choice == Area.choices.RHOMBUS: from mathmod.area import area_rhombus as rhombu do = float( input(_("What is the length of the first diagonal? "))) ds = float(input( _("What is the length of the 2nd diagonal? "))) area = rhombu(do, ds) logging.info( "User used Rhombus area with variable do=%s, ds=%s, answer=%s" % (do, ds, area)) elif choice == Area.choices.TRAPEZIUM: from mathmod.area import area_trapezium as trapezi a = float( input( _("What is the length of the 1st set of parallel sides? " ))) b = float( input( _("What is the length of the 2nd set of parallel sides? " ))) h = float(input(_("What is the height of the trapezium? "))) area = trapezi(a, b, h) logging.info( "User used Trapezium area with variable a=%s, b=%s, h=%s, answer=%s" % (a, b, h, area)) elif choice == Area.choices.CIRCLE: from mathmod.area import area_circle as circl r = float(input(_("What is the radius of the circle? "))) area = circl(r) logging.info( "User used Circle area with variable r=%s, answer=%s" % (r, area)) elif choice == Area.choices.SEMICIRCLE: from mathmod.area import area_semicircle as semi r = float(input(_("What is the radius of the semicircle? "))) area = semi(r) logging.info( "User used Semicircle area with variable r=%s, answer=%s" % (r, area)) elif choice == Area.choices.CIRCULAR_SECTOR: from mathmod.area import area_circular_sector as cirsector r = float( input(_("What is the radius of the circular sector? "))) a = float( input( _("What is the angle of the circular sector *in degrees*? " ))) area = cirsector(r, a) logging.info( "User used Cirsector area with variable r=%s, a=%s answer=%s" % (r, a, area)) elif choice == Area.choices.RING: #my precious! from mathmod.area import area_ring as myprecious ro = float(input( _("What is the radius of the outer circle? "))) rs = float(input( _("What is the radius of the inner circle? "))) area = myprecious(ro, rs) logging.info( "User used Ring area with variable ro=%s, rs=%s answer=%s" % (ro, rs, area)) elif choice == Area.choices.ELLIPSE: from mathmod.area import area_ellipse as el a = float(input(_("What is the length of the major axis? "))) b = float(input(_("What is the length of the minor axis? "))) area = el(a, b) logging.info( "User used Ellipse area with variable a=%s, b=%s answer=%s" % (a, b, area)) if choice in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]: cprint.info(_("The area is: %s") % area) break