Answer to Question #334308 in Python for sandhya

Question #334308

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


1
Expert's answer
2022-04-27T13:24:14-0400
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()

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS