打印一定数量的字符

Printing a set amount of characters

这是学校的一个项目,我对 python 中的编码还很陌生。

基本上,我正在制作一个程序来打印一定数量的“X”和空格,例如X X X X X... 但是,我希望用户选择他们想要打印多少个“X”和空格。

这就是我到目前为止所做的一切:

xnum = input("Choose the amount of 'X's you would like to be printed")
xnum = xnum.upper()
spacenum = input("Choose the amount of spaces you would like to be printed")
linenum = input("Choose how many characters you would like to be displayed on one line")

我想了解如何让程序打印用户要求的“X”的数量,以及空格。

PS:我已经有了每行多少个字符的代码,我只需要一些帮助来打印设定数量的“X”和空格。

此代码假定您所说的字符是指 'X' 而不是 space。

xnum = int(input("Choose the amount of 'X's you would like to be printed\n"))
spacenum = int(input("Choose the amount of spaces you would like to be printed\n"))
linenum = int(input("Choose how many characters you would like to be displayed on one line\n"))

for i in range(xnum):
    if(i%linenum==0 and i!=0):
        print("")
    print("X", end="")
    if(spacenum!=0):
        print(" ", end="")
        spacenum -= 1