Python- slicing operation

Problem description The
use of letters can form some beautiful graphics, an example is given below:

ABCDEFG

BABCDEF

CBABCDE

DCBABCD

EDCBABC

This is a graph with 5 rows and 7 columns. Please find out the regularity of this graph and output a graph with n rows and m columns.

Input format
Enter a line, containing two integers n and m, respectively representing the number of columns of the number of rows of the graph you want to output.
Output format
Output n lines, each m characters, for your graphics.
Sample input
5 7
Sample output
ABCDEFG
BABCDEF
CBABCDE
DCBABCD
EDCBABC
Data scale and convention
1 <= n, m <= 26.

Code:

n,m=map(int,input().split())    # 一行同时输入两个数
s="ABCDEFGHIJKLMNOPQRSTUVWXYZ"

for i in range(0,n):
    s1=s[1:i+1:]
    s2=s[:m-i:]
    print(s1[::-1]+s2)
Published 15 original articles · praised 6 · visits 38

Guess you like

Origin blog.csdn.net/weixin_46165788/article/details/105523543