Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/297.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 2.7中使用for进行水平打印_Python_Python 2.7 - Fatal编程技术网

在Python 2.7中使用for进行水平打印

在Python 2.7中使用for进行水平打印,python,python-2.7,Python,Python 2.7,我对python有一些问题,我无法解决。当用户输入一个单词时,我想打印一个单词的重复,然后他会告诉我这个单词将重复多少次。顺便说一句,我不能。这里是到目前为止的代码 b = raw_input 'enter word' c = input 'enter the amount of time the word will repeat' for g in range (c) print (b) 就像你们看到的,你们可以看到输入的重复,但在垂直线上,我怎么能水平打印呢 这是你的做法 imp

我对python有一些问题,我无法解决。当用户输入一个单词时,我想打印一个单词的重复,然后他会告诉我这个单词将重复多少次。顺便说一句,我不能。这里是到目前为止的代码

b = raw_input 'enter word'
c = input 'enter the amount of time the word will repeat'

for g in range (c)
    print (b)
就像你们看到的,你们可以看到输入的重复,但在垂直线上,我怎么能水平打印呢

这是你的做法

import sys
b = raw_input('enter word')
c = input('enter the amount of time the word will repeat')

for g in range (c):
    sys.stdout.write(b)

很简单。只需添加逗号

print (b),
因此,您的代码变成:

b = raw_input('enter word: ')
c = input('enter the amount of time the word will repeat: ')

for g in range (c):
    print b,
可能重复的