Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Printing python modulus operator as it is over command line

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))

like image 588
None-da Avatar asked Dec 29 '22 20:12

None-da


1 Answers

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

print 'computing %s %% %s' % (num1, num2)
like image 94
RexE Avatar answered Jan 26 '23 12:01

RexE