String Length Info
Programming Interview
Easy
5 views
Problem Description
Input is a single string s is provided (can contain spaces). Output its length, first character and last character. If string is empty, output 0 - -.
Input Format
One line string.
Output Format
One line: len first last.
Official Solution
import sys
s=sys.stdin.read()
if s is None: sys.exit(0)
if s.endswith('\
'):
s=s[:-1]
if len(s)==0:
sys.stdout.write('0 - -')
else:
sys.stdout.write(f'{len(s)} {s[0]} {s[-1]}')
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!