livepython.net

100. Python Program to Print the First and Last Character of a String

EasyIndex and slice

Overview

Use string indexes, including a negative one, to pick single characters.

Problem Statement

Read a word (or a short sentence) and print its first character and its last character, each on its own line. For example, for Sunny:

First: S
Last: y

Use input() with no prompt text: the tests type the input for you, and a prompt would end up in your output.

Input

One line of text. Example:

Sunny

Output

The output for that example:

First: S
Last: y

The tests try 4 different inputs, including a one-letter word.

Learn this firstChapter 12 · Python String Indexing and Slicing
solution.py
# write your code here

EXPECTED OUTPUT

1First: S
2Last: y

YOUR OUTPUT

Press Run to see your output here. Lines are compared with the expected output.