我正在做一個python 3的初學者課程,並且必須形成一個星號三角形,輸出如下。 Asterisk triangle formatAsterisk三角形Python(附輸入)
我嘗試到目前爲止看起來如下:
def printRow(c, length) :
line = c * length
print(line)
myLen = 0
stars ="*"
n = myLen-1
spaces = (' '*n)
myLen = int(input("Enter number to make triangle: "))
if myLen<=0 :
print("The value you entered is too small to display a triangle")
elif myLen>=40 :
print("the value you entered is too big to display on a shell window")
while myLen>0 :
print(spaces, stars, myLen)
myLen = myLen-1
This is what it outputs in the shell
從這一點上,我完全迷失了方向,所以任何幫助,將不勝感激。
你在倒數第二行調用'print',而不是'printRow'函數。 – Jeff