I am writing a program that reads three lines of input. The first line will be a word, then a number of characters to repeat, then a number of repeats. But unfortunately I am unable to do it can any one guide me by looking at my code. Thanks
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
I’m afraid you’re doing something wrong.
I suppose you got the following error:
AttributeError: 'str' object has no attribute 'repeat'Since there is no
repeat()method forstrin Python.And I guess you may want this:
EDITED:
I see.. Your edit seems to say you want to repeat the last
lengthofword..Then try
word + word[-length:] * (count - 1)