gpt4 book ai didi

python - 在 Python 2.7 中使用 for 水平打印

转载 作者:行者123 更新时间:2023-11-28 21:16:03 28 4
gpt4 key购买 nike

我有 python 的问题,我无法弄清楚。我想在用户输入一个词时打印一个词的重复,然后他会告诉这个词将重复多少次。我不能 * 顺便说一下。到目前为止这里的代码

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

for g in range (c)
print (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,

关于python - 在 Python 2.7 中使用 for 水平打印,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29293577/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com