Question

I want to print modulus operator as it is over the command line: E.g this is how the output should look like:
1%2
2%4

or
30%
40%

I am using the print statement like this:

print 'computing %s % %s' % (num1, num2)

Its throwing the default error:

TypeError: not all arguments converted during string formatting

For now I am using:

print 'computing 1'+'%'+'2'

which prints:

computing 1%2

But tell me how to get this done using the first approach(:print 'computing %s % %s' % (num1,num2))

Was it helpful?

Solution

Escape the % sign with another % sign, like this:

print 'computing %s %% %s' % (num1, num2)

OTHER TIPS

print 'computing %s %% %s' % (num1, num2)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top