Python 2.7中使用for水平打印

2024-04-20 11:01:13 发布

您现在位置:Python中文网/ 问答频道 /正文

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

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

for g in range (c)
    print (b)

就像你看到的,你可以看到重复的输入,但在垂直线上,我怎么能打印水平?在


Tags: ofthe代码用户inforinputraw
2条回答

下面是你的方法

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),

所以你的代码变成:

^{pr2}$

相关问题 更多 >