0
Can any one please explain me this code
def f(s,k): if k <= 0: for n in s: print(n) return # in case if k >= 1 for sl in range(len(s)): i = sl % k if (sl // k) % 2 == 1: i = k - i print(" " * i, s[sl]) # main block n="sjjsnehbhhHCXcifOHbhjjkkk" print(len(n)) print () print () f(n,5)
2 Answers
0
It is complete nonsense. First block of function will never run since k always 5 and second part of function will return type error from using string arg on modulus operator. All it should do is print 25. Why have you put this here??
0
Sorry misinterpreted this. First bit of function still seems pointless since k always 5 and presumably there in case k altered . Second bit generated a series of numbers running up and down to 8 and uses them to control spaces . Actuallly quite nice. Can watch it work with:
def f(s,k):
if k <= 0:
for n in s:
print(n)
return
# in case if k >= 1
for sl in range(len(s)):
i = sl % k
print (i)
if (sl // k) % 2 == 1:
i = k - i
print ("conditional",i)
print ( "final", i)
#print(" " * i, s[sl])
# main block
n="sjjsnehbhhHCXcifOHbhjjkkk"
print(len(n))
print ()
print ()
f(n,8)



