[英]How to find tens/ones digit of two different numbers regardless of their length
sorry if this is the wrong place for this question or anything. 很抱歉,如果这是该问题或任何其他错误的地方。 I picked up a book on python and I'm trying to learn the basics by myself right now.
我拿起了一本关于python的书,现在我正试图自己学习基础知识。 My question is, if I'm given two different numbers, is there a way I can find the tens and ones digit of both numbers, regardless of the length of each number?
我的问题是, 如果给我两个不同的数字,有没有办法找到两个数字的十位数和个位数,而不管每个数字的长度如何? How would I go about doing this?
我将如何去做呢? I'm trying to use floor division and modulo because that makes sense but I can't get it quite right.
我正在尝试使用地板除法和取模,因为这很有意义,但我做不到。 In the future, how should I approach things like this?
将来,我应该如何处理这样的事情? Thanks so much!
非常感谢!
Modulo and floor division is probably the best way to go for large numbers: 模和地板划分可能是处理大量数据的最佳方法:
num = 1327419832467138974619485762453
# Tens
print(num % 100 // 10)
# Ones
print(num % 10)
Output: 输出:
5
3
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.