指定された桁数を指定された桁から抽出するPythonプログラム

指定された桁数を指定された桁から抽出するPythonプログラム

0から始まらない数字から、指定された桁数を指定された桁から抜き出すPythonプログラムです。

入力例

1234567891
5
3

出力例

567

Pythonプログラム

string = int(input())
start_str = int(input())
digit = int(input())
string_digit = int(len(str(string)))
a = int(string / 10 ** (string_digit - start_str - digit + 1))
b = int(a / 10 ** digit)
b  = b * 10 ** digit
result = a - b
print(result)

書き方が汚いのはご愛嬌ということでよろしくおねがいします。

GitHub Gist

Python program to extract a specified number of digits from a specified number of digits.
Python program to extract a specified number of digits from a specified number of digits. - main.py