Added dec formatting and checking multiple 0 answers.
| | |
| | | def checkAnsProximity(self, ans): |
| | | for idx1, (val1, cor) in enumerate(ans): |
| | | for idx2, (val2, cor) in enumerate(ans): |
| | | |
| | | if idx1 == idx2: |
| | | continue |
| | | |
| | | if (val1.get_formatted_value()==val2.get_formatted_value()): |
| | | return True |
| | | if not val1.is_float() or not val2.is_float(): |
| | | if val1.get_formatted_value() == val2.get_formatted_value(): |
| | | return True |
| | |
| | | for __corrsplit in __corr.split(";"): |
| | | __result = None |
| | | if __corrsplit.find("=") >= 0: |
| | | exec(self.substitute_octave(__corrsplit)) |
| | | try: |
| | | exec(self.substitute_octave(__corrsplit)) |
| | | except: |
| | | print("Error while evaluating {}".format(__corrsplit)) |
| | | else: |
| | | __result = eval(self.substitute_octave(__corrsplit)) |
| | | if __result is None: |
| | |
| | | elif type == "prefix": |
| | | return PrefixFloatFormatter(arglist) |
| | | elif type == "dec" or type == "decimal": |
| | | return EngFloatFormatter(arglist) # fallback to engineering |
| | | return DecFloatFormatter(arglist) |
| | | else: |
| | | return None |
| | | |
| | |
| | | def getValue(self, string): |
| | | return string |
| | | |
| | | class DecFloatFormatter(FormatterFactory): |
| | | def __init__(self, formatparameters): |
| | | if len(formatparameters) != 1: |
| | | raise Exceptions.WrongParameters("Dec format accept only one argument") |
| | | self.precision = int(formatparameters[0]) |
| | | |
| | | def toFormat(self, num): |
| | | try: |
| | | num = float(num) |
| | | except ValueError: |
| | | raise ValueError |
| | | except TypeError: |
| | | raise ValueError |
| | | |
| | | |
| | | return ( |
| | | ("{:." + str(self.precision - 1) + "f}").format(num).replace(".", ",\!") |
| | | ) |
| | | |
| | | def getValue(self, num): |
| | | val = ("{:." + str(self.precision - 1) + "f}").format(num) |
| | | return float(val) |
| | | |
| | | |
| | | |
| | | class SciFloatFormatter(FormatterFactory): |
| | | def __init__(self, formatparameters): |
| | |
| | | |
| | | #StartSkalar |
| | | ime: r0 |
| | | izpis: dec 1 |
| | | izpis: dec 3 |
| | | nacin: FixedVals 5e-3 6e-3 8e-3 |
| | | #EndSkalar |
| | | |