Home python Error “not all arguments converted during string formatting”

Error “not all arguments converted during string formatting”




Learning to code in Python. I don’t know what I did wrong …

Answer 1, authority 100%

With this code, Python does not understand what the type of the variable you entered is.
Try changing your code to x = int (input ()) .
Even the error itself says about string format

Answer 2, authority 100%

The % operator in Python works differently depending on the type of object it applies to:

  1. Gives the remainder of division when applied to numbers: 3% 2 = 1
  2. For strings, apply as format operator :
    "Result is% s parrots"% 48 becomes "Result is 48 parrots"

You are applying an operator to strings (the input () function returns strings), so Python tries the second option. But since there are no “markers” for substitution in the first line (like % s inside the line in the example above), then you get the error “not all arguments were converted during formatting”.

In your case, you just need to convert the entered data to numbers.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions