热线电话:13121318867

登录
2019-02-21 阅读量: 666
如何将某串连续字符按阶梯形输出?

# Python code 3.x to demonstrate star pattern

# Function to demonstrate printing pattern of alphabets

def contalpha(n):

# initializing value corresponding to 'A'

# ASCII value

num = 65

# outer loop to handle number of rows

- for i in range(0, n):

# inner loop to handle number of columns

# values changing acc. to outer loop

for j in range(0, i+1):

# explicitely converting to char

ch = chr(num)

# printing char value

print(ch, end=" ")

# incrementing at each column

num = num +1

# ending line after each row

print("\r")

# Driver code

n = 5

contalpha(n)

输出:

A 
BC
DEF
GHIJ
KLMNO
0.0000
1
关注作者
收藏
评论(0)

发表评论

暂无数据
推荐帖子