I can not find a mistake! Help me please.
Code:

a = input('делимое') b = input('делитель') print('Ответ: {:.2%}'.format(a/b)) 

Closed due to the fact that off-topic participants jfs , Dmitriy Simushev , Nicolas Chabanovsky Jun 4 '16 at 6:22 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • “Questions asking for help with debugging (“ why does this code not work? ”) Should include the desired behavior, a specific problem or error, and a minimum code for playing it right in the question . Questions without an explicit description of the problem are useless for other visitors. See How to create minimal, self-sufficient and reproducible example . " - jfs, Dmitriy Simushev, Nicolas Chabanovsky
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • one
    Did you try to execute the code in the question? What did you expect to receive? What happens instead — describe in detail. If you see errors in the console, copy them to the question as is (full traceback). What is your version of Python? Axis? - jfs

1 answer 1

The input() function returns strings, not numbers. Before dividing, you need to convert them into numbers, like this:

 a = int(input('делимое')) b = int(input('делитель')) ... 

if you need integers, or

 a = float(input('делимое')) b = float(input('делитель')) ... 

if floating point numbers are needed.

The next time you ask a question in error, indicate the error in the text of the question. In this case, it is not critical, because The code is small, but generally it is always better to specify.

  • @jfs, interestingly, it turns out that input() in Python2 is more intelligent than in Python3. - insolor
  • [unsuccessfully comment updated] If we consider the example as Python 2 code, then the code can already work as is (although it is better to use float(raw_input()) explicitly). Maybe OP does not know that 1/2==0 in Python 2 or how the % format works. Share your mind reading equipment;) - jfs
  • @jfs, well, at least he uses print as in Python3, although this still doesn’t mean anything. Assuming that this is Python3, then the error is that the input data is not converted to numbers. Although it may still be Python2, and the author really did not expect to see the answer as a percentage. - insolor