如何在用户输入为中间线宽度的情况下制作菱形?

2024-10-03 13:24:32 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在进行函数和参数练习:

Write a function that will print out a "diamond" of any size and with any symbol specified by the user. The size is the width of the diamond. Test it.

我试着在网上搜索我的问题的答案,但是所有的答案都有用户输入的行数,这不是我想要的。到目前为止,我的代码是令人满意的。有什么帮助吗

userSize = int(input("Enter size: "))
userSymbol = input("Enter symbol: ")

def drawCross(symbol, size):
    num = 0
    for i in range(1, size + 1):
        for j in range(1, (size - i) + 1):
            print(end=" ")

drawCross(userSymbol, userSize)

Tags: ofthe答案inforinputsizeany