0
def leakyPipes(n):
if (n > 0):
    if (n % 4 == 0):
        print("drip %d" % n)
        leakyPipes(n-3)
    if (n % 3 == 0):
        print("drop %d" % n)
leakyPipes(12)

What is each of the % in print("drip %d" % n) supposed to do in this situation? The terminal output is giving me this:

drip 12
drop 9
drop 12
darkhorse
  • 33
  • 1
  • 2

3 Answers3

2

It's a formatting specifier. %d would mean digit, %s would mean string, etc etc.

nigel239
  • 1,485
  • 1
  • 3
  • 23
0

Using that method (using % formatter) is not that great.

A better choice would be to use "str.format" or better yet f-string

You problem, and the 2 other options are outlined on the following page.

Python String Formatting Options

0

The %d is used to specify the format, %d means a digit and %s means a string. The % that is used after the " is used so the program knows that n should be placed on the format specifier. Equally, you could use print("drop", n).\

A useful link could be: https://www.delftstack.com/howto/python/python-print-variable/

BJKoop
  • 11
  • 4