我想遞歸地打印出一個空心正方形。我不知道如何重寫函數def hollowSquare()
以進行遞歸調用。
注意:我必須在這個賦值的hollowSquare函數中有3個參數,count用於跟蹤我正在繪製的地方。遞歸重寫函數
def validateInput():
n =True
while n != False:
height = int(input("Please enter the height of you square (must be > 0): "))
if height < 0:
validateInput()
else:
symb = input("Please enter a character for your square:")
return(height,symb)
def hollowSquare(height,symb,count):
innerSquare = height -2
print ('*' * height)
for i in range(innerSquare):
print ('*' + ' ' * innerSquare + '*')
print ('*' * height)
def main():
height,symb = validateInput()
count =0
hollowSquare(height,symb,count)
main()
有''請輸入''表示您不能輕易自動測試它。我希望學校會先教測試。 –