輸入一行字符串及下標,能取出相應字符。程序能對不合法數據做相應異常處理。
輸入格式:
- 行1:輸入一字符串
- 行2:輸入字符下標
輸出格式:
- 下標非數值異常,輸出
下標要整數
- 下標越界,輸出
下標越界
- 數據正確,輸出下標對應的字符
輸入樣例:
python
1
輸出樣例:
y
輸入樣例:
python
a
輸出樣例:
下標要整數
輸入樣例:
python
10
輸出樣例:
下標越界
try: s = input() x = input() print("{}".format(s[int(x)])) except ValueError: print("下標要整數") except IndexError: print("下標越界")