first_two

Take a string as input, print out the string made of its first two chars, so the String "Hello" yields "He". If the string is shorter than length 2, return whatever there is, so "X" yields "X", and the empty string "" yields the empty string "". Note that len() returns the length of a string.

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'

Output:

'He'

Test 2

Input:

'abcdefg'

Output:

'ab'

Test 3

Input:

'ab'

Output:

'ab'

Test 4

Input:

'a'

Output:

'a'

Test 5

Input:

''

Output:

''

Test 6

Input:

'Kitten'

Output:

'Ki'

Test 7

Input:

'hi'

Output:

'hi'

Test 8

Input:

'hiya'

Output:

'hi'