Character At Position
Python
Easy
2 views
Problem Description
String s and position p are provided (0-based). Output character at that position. If p is not integer or out of range, output INVALID.
Input Format
Line1 s. Line2 p.
Output Format
One character or INVALID.
Official Solution
import sys
lines=sys.stdin.read().splitlines()
if len(lines)<2:
sys.stdout.write('INVALID')
else:
s=lines[0]
try:
p=int(lines[1].strip())
sys.stdout.write(s[p])
except Exception:
sys.stdout.write('INVALID')
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!