SNAKY CONVERSION
you are given a string S print the string in N rows containing a snaky pattern represenation as described below
INPUT:the first line should be a string
explanation:
s=AWESOMENESS N=4
consider the following snaky representation of the word
A E
W M N
E O E S
S S
the first row contains characters AE
the 2nd row contains characters WMN
the 3rd row contains characters EOES
THE fourth row contains characters SS
INPUT:
NEWSLETTER 3
OUTPUT:
NLE
ESETR
WT
INPUT:AWESOMENESS 4
OUTPUT:
AE
WMN
EOES
SS
s_tmp, n_tmp = input("Enter s and n (separate space)").split(' ')
s = s_tmp
n = int(n_tmp)
snake = []
number = 0
k = 0
for i in range(n):
snake.append([])
for i in range(len(s)):
number += k
if number == 0:
k = 1
elif number == n-1:
k = -1
snake[number].append(s[i])
for i in range(n):
for j in range(len(snake[i])):
print(snake[i][j], end='')
print()
Comments
Leave a comment