Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何创建一个具有输出的程序,以便在每个字母向下移动时将其重复一次?_Python - Fatal编程技术网

Python 如何创建一个具有输出的程序,以便在每个字母向下移动时将其重复一次?

Python 如何创建一个具有输出的程序,以便在每个字母向下移动时将其重复一次?,python,Python,使用python,我怎样才能让一个out看起来像这个doogg,这样它的每个字母都会重复一次。我试过这样的东西 # Program 21 def double(source): pile = "" for letter in source: pile = pile+letter+letter print pile print pile 但结果看起来像 dd ddoo ddoogg 我想你应该试试看 def double(source): word = []

使用python,我怎样才能让一个out看起来像这个doogg,这样它的每个字母都会重复一次。我试过这样的东西

# Program 21
def double(source):
  pile = ""
  for letter in source:
    pile = pile+letter+letter
    print pile
  print pile
但结果看起来像

dd
ddoo
ddoogg
我想你应该试试看

def double(source):
    word = []
    for x in range(len(source)):
        word.append(source[x]*(x+1))
        print ''.join(map(str, word))


double("dog")

input()
如果您希望将所有内容都放在一行中,请在python 2中尝试以下内容:

def double(source):
    word = []
    for x in range(len(source)):
        word.append(source[x]*(x+1))
    print ''.join(map(str, word)),


double("dog")

input()
对于python 3,这是:

def double(source):
    word = []
    for x in range(len(source)):
        word.append(source[x]*(x+1))
    print(''.join(map(str, word)), end="")


double("dog")

input()

伪代码ish:
用于。。。;i++;比我快多了!天才乔兰·比斯利!。。。当然更干净了!这将是完美的,但我不希望它像它那样一行走下去,我只想要像Dooggso一样的一行你想要它全部在一行上吗?是的,那将是greatI,我想我也为python 2添加了一个版本-你能帮我测试一下吗?甜心,很高兴我能帮上忙
def double(source):
    word = []
    for x in range(len(source)):
        word.append(source[x]*(x+1))
    print(''.join(map(str, word)), end="")


double("dog")

input()