我必须在屏幕中间制作一个字母金字塔我可以打印金字塔但似乎无法获取字母表并进入
I have to make a pyramid of letters in the middle of the screen i am able to print the pyramide but can not seem to get the alphabet and to go in
https://i.stack.imgur.com/5rpBR.png
https://i.stack.imgur.com/ZH04N.png
def full_pyramid(行):
print('\nFull pyramid...\n')
for i in range(rows):
print(' '*(rows-i-1) + '*'*(2*i+1))
字符串=“”
reversed_string = 字符串[::-1]
result_string = " ".join(string)
对于范围 (0 ,25):
result_string += chr(ord('a')+a)
应该这样做
import string
rows = 26
for i in range(rows):
row = string.ascii_letters[i]
for c in range(i-1,-1,-1):
outside = string.ascii_letters[c]
row = '%s%s%s' % (outside, row, outside)
space = ' '*(rows-i)
row = '%s%s%s' % (space, row, space)
print(row)
这样就可以了
Python 3.x :
def pyramid(rows):
s = "abcdefghijklmnopqrstuvwxyz"
for i in range(rows, 0, -1):
for j in range(i):
print(' ', end='')
for k in range(rows-i):
print(s[k], end='')
for m in range(rows-i, -1, -1):
print(s[m], end='')
print()
pyramid(15)
Python 2.x :
def pyramid(rows):
s = "abcdefghijklmnopqrstuvwxyz"
for i in range(rows, 0, -1):
for j in range(i):
print(' '),
for k in range(rows-i):
print(s[k]),
for m in range(rows-i, -1, -1):
print(s[m]),
print('')
pyramid(15)
https://i.stack.imgur.com/5rpBR.png
https://i.stack.imgur.com/ZH04N.png
def full_pyramid(行):
print('\nFull pyramid...\n')
for i in range(rows):
print(' '*(rows-i-1) + '*'*(2*i+1))
字符串=“”
reversed_string = 字符串[::-1]
result_string = " ".join(string)
对于范围 (0 ,25):
result_string += chr(ord('a')+a)
应该这样做
import string
rows = 26
for i in range(rows):
row = string.ascii_letters[i]
for c in range(i-1,-1,-1):
outside = string.ascii_letters[c]
row = '%s%s%s' % (outside, row, outside)
space = ' '*(rows-i)
row = '%s%s%s' % (space, row, space)
print(row)
这样就可以了
Python 3.x :
def pyramid(rows):
s = "abcdefghijklmnopqrstuvwxyz"
for i in range(rows, 0, -1):
for j in range(i):
print(' ', end='')
for k in range(rows-i):
print(s[k], end='')
for m in range(rows-i, -1, -1):
print(s[m], end='')
print()
pyramid(15)
Python 2.x :
def pyramid(rows):
s = "abcdefghijklmnopqrstuvwxyz"
for i in range(rows, 0, -1):
for j in range(i):
print(' '),
for k in range(rows-i):
print(s[k]),
for m in range(rows-i, -1, -1):
print(s[m]),
print('')
pyramid(15)