【发布时间】:2020-04-28 11:45:40
【问题描述】:
所以我试图在同一行打印多个函数输出,而不是字符串,我知道我们可以在 python 3.0 及更高版本中使用 end=" 但这是不同的场景,我尝试迭代函数但没有用,我一直在尝试,但我想知道如何解决这个问题,我仍然是初学者,所以有任何帮助,还请检查我的代码和示例输出
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
*******
*
*
*
*
*
*******
*******
* *
* *
* *
* *
* *
*******
*******
*
*
*
*******
*
*
*
*******
*******
*
*
*
*
*
*
*******
*
*
*
*
*
*******
*******
* *
* *
* *
* *
* *
*******
但我想要更多像在一行中 喜欢
COSTCO
但不是
C
O
S
T
C
O
【问题讨论】:
标签: python-3.x function object printing output