Rounding, variable from a .txt in Python 3 and extra

118 views Asked by At
if op in ["/"]:
    # rounding does not rounds half up so I imported a module
    from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_DOWN
    Decimal(str(answer)).quantize(Decimal("1.11"), rounding=ROUND_HALF_UP)
    Decimal(str(given_answer)).quantize(Decimal("1.11"), rounding=ROUND_HALF_UP)
print("correct {}".format(answer, ".2f"))

49//34=?1.44

correct 1

Wrong answer!

I want it to have the right answer as 3.56 if the real answer is 3.55865465. What am I doing wrong?

Written text file with python

1

There are 1 answers

2
Stian On BEST ANSWER

Try changing the last line to the following:

print("correct {:.2f}".format(answer))