热线电话:13121318867

登录
2019-02-21 阅读量: 1865
python如何将字符阶梯型输出?

以下代码用来实现阶梯型字符的输出:

# Function to demonstrate printing pattern of alphabets

def alphapat(n):

# initializing value corresponding to 'A'

# ASCII value

num = 65

# outer loop to handle number of rows

# 5 in this case

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 number

num = num + 1

# ending line after each row

print("\r")

# Driver Code

n = 5

alphapat(n)

输出:

A 
BB
CCC
DDDD
EEEEE
75.0000
6
关注作者
收藏
评论(0)

发表评论

暂无数据
推荐帖子