Python 3.x 打印“;“多功能输出”;[不仅仅是打印字符串]在Python的同一行中

Python 3.x 打印“;“多功能输出”;[不仅仅是打印字符串]在Python的同一行中,python-3.x,function,object,printing,output,Python 3.x,Function,Object,Printing,Output,所以我试图在同一行中打印多个函数的输出,而不是字符串,我知道我们可以使用end=“在Python3.0及以上版本中,但这是不同的场景,我尝试了迭代函数,但没有效果,我一直在尝试,但我想了解如何实现这一点,我还是一个初学者,所以有什么可以帮助的,也请检查我的代码和示例输出 class Costco: def __init__(self,n): self.n=n def letterC(self): print('*'*self.n) for i in range(self.n

所以我试图在同一行中打印多个函数的输出,而不是字符串,我知道我们可以使用end=“在Python3.0及以上版本中,但这是不同的场景,我尝试了迭代函数,但没有效果,我一直在尝试,但我想了解如何实现这一点,我还是一个初学者,所以有什么可以帮助的,也请检查我的代码和示例输出

class Costco:

 def __init__(self,n):
   self.n=n

 def letterC(self):
  print('*'*self.n)
  for i in range(self.n-2):
    print('*')
  print('*'*self.n)



 def letterO(self):
  print('*'*self.n)
  for i in range(self.n-2):
    print('*'+' '*(self.n-2)+'*')
  print('*'*self.n)


 def letterS(self):
  print('*'*self.n)
  for i in range(int(self.n/2)):
    print('*')
  print('*'*self.n)
  for i in range(int(self.n/2)):
    print(' '*(self.n-1)+'*')
  print('*'*self.n)


 def letterT(self):
  print('*'*self.n)
  for i in range(self.n-1):
    print(' '*int(self.n/2)+'*')


c1=Costco(int(input('please enter an odd number:\n')))
while c1.n%2==0:
   print('you entered an even number,please enter only odd number')
   c1=Costco(int(input('please enter an odd number:\n')))

def cost(c1):
  for i in [c1.letterC,c1.letterO,c1.letterS,c1.letterT,c1.letterC,c1.letterO]:
    i()


cost(c1)
因此,示例输出如下所示

please enter an odd number:
7
*******
*
*
*
*
*
*******
*******
*     *
*     *
*     *
*     *
*     *
*******
*******
*
*
*
*******
      *
      *
      *
*******
*******
   *
   *
   *
   *
   *
   *
*******
*
*
*
*
*
*******
*******
*     *
*     *
*     *
*     *
*     *
*******
但我想要更多的像在一条线上 像

但不是

C
O
S
T
C
O

这个print函数在您要求它打印的内容的末尾插入一个换行符,因此每次调用print(),您都会将层移低一层。处理此问题的一种方法是将每个字符存储为字符串数组,每个字符串包含要打印的行

所以C[0]将是“******”,C[1]将是“*”,C[6]将是“*****”

然后使用for循环一次打印一层字符,在每个组件之间插入一个空白字符。有点像印刷品(c[i]+o[i]+s[i]+t[i]+c[i]+o[i])

唯一需要注意的是,您必须事先一层一层地定义每个字符,并更改打印“S”的方式,使其具有与其他字符相同的层数

C
O
S
T
C
O