Problem 155706 · easy · Phase 01 Prerequisites & Setup

Middle of the Word

strings · indexing · slicing · len · modulo

Given a non-empty string s, return its middle character. If the length is even there is no single middle, so return the two middle characters together.

Examples

Input:  s = "hello"
Output: "l"

Input:  s = "test"
Output: "es"

Constraints

  • 1 <= len(s) <= 2000
  • s may contain any printable characters

Goals

  • Compute the middle index from the length
  • Return one character for odd lengths and two for even lengths
Starting Python…