我想递归地打印出一个空心正方形。我不知道如何重写函数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()
有''请输入''表示您不能轻易自动测试它。我希望学校会先教测试。 –