定义函数,请用户输入整数 M 和整数 N 。取输出整数 M 第 N 位上的值。
时间: 2024-02-18 14:00:13 浏览: 28
好的,这是一个简单的问题。下面是 Python 代码实现:
```python
def get_digit(m, n):
"""
获取整数 M 第 N 位上的值
:param m: 整数 M
:param n: 第 N 位
:return: 第 N 位上的值
"""
return int(str(m)[n - 1])
```
使用该函数,你可以通过以下方式获取整数 M 的第 N 位上的值:
```python
m = 12345
n = 2
print(get_digit(m, n)) # 输出 2
```
请注意,这个函数假设整数 M 是正数,并且 N 是一个合法的位数(即 N 大于 0 且小于等于 M 的位数)。如果 M 是负数,则需要对函数进行修改。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![c](https://img-home.csdnimg.cn/images/20210720083646.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![py](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)