repeat_end

Requirements:

  • substrings and slicing

  • loop with a counter variable

  • string building and filtering

Get from user input a string and integer we will call n. Output a string made of n repetitions of the last n characters of the string. You may assume that n is between 0 and the length of the string, inclusive.

This exercise was taken from codingbat.com and has been adapted for the Python language. There are many great programming exercises there, but the majority are created for Java.

Test 1

Input:

'Hello'
3

Output:

'llollollo'

Test 2

Input:

'Hello'
2

Output:

'lolo'

Test 3

Input:

'Hello'
1

Output:

'o'

Test 4

Input:

'Hello'
0

Output:

''

Test 5

Input:

'abc'
3

Output:

'abcabcabc'

Test 6

Input:

'1234'
2

Output:

'3434'

Test 7

Input:

'1234'
3

Output:

'234234234'

Test 8

Input:

''
0

Output:

''