sizePy=int(input('Enter number of lines: '))
charPy = raw_input("Enter the character: ")
for i in range(1,sizePy+1):
print ((sizePy-i)*' '+i*"%s " %charPy)
sizePy=int(input('Enter number of lines: '))
charPy = input("Enter the character: ")
for i in range(1,sizePy+1):
print ((sizePy-i)*' '+i*"{0}".format(charPy))
如果您使用的是
Python3
,那么下面的方法可能会起作用您的错误是由以下原因造成的:
在应用
*
操作符之后,例如,如果i是5,这将是:你只有一个
charPy
和5个%s
。要解决此问题,请将其更改为:其中Python将首先进行
charPy
替换,然后重复该字符串i
次相关问题 更多 >
编程相关推荐