pile1_str = "pile 1: "
x="O"
y=1
while y <= pile1: #pile1 being the number of chips the user inputs
pile1_str = pile1_str + x
print(pile1_str)
y= y+1
以下是您输入时应该看起来的样子,比如12个硬币:
pile 1: OOOOO OOOOO OO
在每第n个(第5个)字符后,如何在字符串中插入空格?
答案 0 :(得分:1)
pile1_str = "pile 1: "
x="O"
y=1
while y <= pile1:
pile1_str = pile1_str + x
if y%1==0:
pile1_str = pile1_str + " "
print(pile1_str)
y= y+1
答案 1 :(得分:1)
length = 19
groupSize = 5
pile = 'O' * length
spacedPile = ' '.join(pile[i:i+groupSize] for i in xrange(0, len(pile), groupSize))
print spacedPile