Advertisements
Advertisements
Question
Write a user defined function in Python named Puzzle (W, N)
which takes the argument W
as an English word and N
as an integer and returns the string where every Nth alphabet of the word W
is replaced with an underscore ("_").
For example: if W
contains the word "TELEVISION"
and N
is 3, then the function should return the string "TE_EV_SI_N"
. Likewise for the word "TELEVISION"
if N
is 4, then the function should return "TEL_VIS_ON"
.
Code Writing
Solution
def puzzle(w,n):
mystr=""
for i in range(0,len(w)):
if (i+1)%n==0:
mystr += "_"
else:
mystr + = w[i]
print(mystr)
return mystr
shaalaa.com
Is there an error in this question or solution?