python重复错误

python重复错误,python,repeat,Python,Repeat,我正在写一个程序,可以读取三行输入。第一行是一个单词,然后是一些要重复的字符,然后是一些重复的字符。但不幸的是,我无法做到这一点,任何人都可以通过查看我的代码来指导我。谢谢 word = raw_input("Enter the word: ") length = int(raw_input("Enter the repeat length: ")) count = int(raw_input("Enter the repeat count: ")) print word.repeat() *

我正在写一个程序,可以读取三行输入。第一行是一个单词,然后是一些要重复的字符,然后是一些重复的字符。但不幸的是,我无法做到这一点,任何人都可以通过查看我的代码来指导我。谢谢

word = raw_input("Enter the word: ")
length = int(raw_input("Enter the repeat length: "))
count = int(raw_input("Enter the repeat count: "))
print word.repeat() * count
I want this sort of output:
Enter the word: banana
Enter the repeat length: 2
Enter the repeat count: 3
banananana

恐怕你做错了什么。 我想您可能有以下错误:

AttributeError:“str”对象没有属性“repeat”

因为Python中没有str的repeat方法

我猜你可能想要这个:

# gives the first `length` characters in `string` to repeat for `count` times
word[:length] * count 
编辑:

我明白了。。你的编辑似乎说你想重复单词的最后一段


然后尝试word+word[-length:]*count-1

您应该始终给出您得到的输出或错误的示例,并描述它与您想要的不同之处。在您的示例中,您甚至不使用length变量。你希望它能做什么?不@Pengyu CHEN它向我展示了某种语法错误。。!!