the_end

Given a string, return a string length 1 from its front, unless front is false, in which case return a string length 1 from its back. The string will be non-empty.

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'
True

Output:

'H'

Test 2

Input:

'Hello'
False

Output:

'o'

Test 3

Input:

'oh'
True

Output:

'o'

Test 4

Input:

'oh'
False

Output:

'h'

Test 5

Input:

'x'
True

Output:

'x'

Test 6

Input:

'x'
False

Output:

'x'

Test 7

Input:

'java'
True

Output:

'j'

Test 8

Input:

'chocolate'
False

Output:

'e'

Test 9

Input:

'1234'
True

Output:

'1'

Test 10

Input:

'code'
False

Output:

'e'