0

I was attempting a question on edabit (https://edabit.com/challenge/4t6YAJS8dtT7RQjta), for which I got this answer:

def num_layers(no):
    paper_size = 0.0005
    if no == 1:
        paper_size = paper_size * 2
    else:
        paper_size = 1
        paper_size = paper_size * (2 ** (no-1))
    return (str(paper_size / 1000) + 'm')

Though it says that the test was passed, I still receive this error:

FAILED: '1e-06m' should equal '0.001m'
ERROR: Traceback:
   in <module>
  File "./frameworks/python/cw-2.py", line 28, in assert_equals
    expect(actual == expected, message, allow_raise)
  File "./frameworks/python/cw-2.py", line 18, in expect
    raise AssertException(message)
cw-2.AssertException: '1e-06m' should equal '0.001m'

How can I add meters to my answer without it returning this error?

mhhabib
  • 2,975
  • 1
  • 15
  • 29
morgs03
  • 9
  • 1
  • 4
  • 1
    The indentation is clearly wrong. Please [edit] to fix it. On the desktop version of this site, you can easily format code properly by simply pasting it in, selecting the pasted block, and typing ctrl-K. – tripleee Dec 14 '20 at 14:07
  • 1
    First of all, 1e-6 does not equal 0.001. Secondly, see [this question](https://stackoverflow.com/questions/6149006/display-a-float-with-two-decimal-places-in-python) to see how to format the float with more decimal places. – thshea Dec 14 '20 at 14:09
  • 1
    Does this answer your question? [Limiting floats to two decimal points](https://stackoverflow.com/questions/455612/limiting-floats-to-two-decimal-points) – Tomerikoo Dec 14 '20 at 14:34

1 Answers1

0

Thank you for the help. This solved my problem:

def num_layers(no):
    if no == 1:
        return (str(0.001) + 'm')
    else:
        paper_size = 1
        paper_size = paper_size * (2 ** (no-1))
    return (str(paper_size / 1000) + 'm')
morgs03
  • 9
  • 1
  • 4