Skip to content Skip to sidebar Skip to footer

Python: Typeerror - Not All Arguments Converted During String Formatting

I'm writing a basic Python script, the code of which is as followsdef is_prime(n): def is_prime(n): i = 2 while i

Solution 1:

This happens when n in the expression n%i is a string, not an integer. You made x a string, then passed it to is_prime():

>>> is_prime('5')
Traceback (most recent calllast):
  File "<stdin>", line 1, in<module>
  File "<stdin>", line 4, in is_prime
TypeError: notall arguments converted during string formatting
>>> is_prime(5)
True

Pass integers to is_prime() instead:

is_prime(int(x[i:]))

The % operator on a string is used for string formatting operations.

You appear to have forgotten to return anything from truncable(); perhaps you wanted to add:

return li

at the end?

Post a Comment for "Python: Typeerror - Not All Arguments Converted During String Formatting"