简体   繁体   English

如何查找两个不同数字的十位数/一位数字

[英]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.

相关问题 PYTHON输入的数字如何求千位、百位、十位、个位的数字? 例如:256 有 6 个一,5 个十等 - How to find the numbers in the thousands, hundreds, tens, and ones place in PYTHON for an input number? For example: 256 has 6 ones, 5 tens, etc 如何在python中获取两个数字(未知数字长度)之间的子串 - How to get substring between two numbers (of unknown digit length) in python 如何找出 Python 中两个数字之间的哪个数字不同? - How can I find out which digit is different between two numbers in Python? 如何在python中找到由两个三位数组成的最大回文? - How to find the largest palindrome made of two three digit numbers in python? 如何将4位数字变量与4位数字列表进行比较,并确定它们是否具有完全相同的数字,而不管顺序如何? - How Can I Compare A 4 Digit Variable To A List Of 4 Digit Numbers And Determine If They Have The Exact Same Numbers, Regardless Of Order? 检查数字是否在两个不同数字的相同位置 - check if digit is at same position in two different numbers 查找所有三个“两位数字”,没有重复的数字 - Find all three “two digit numbers” with no repeated digit 给定两个相同长度的二进制列表,如何找到与交替列表相对应的所有索引对,而两者之间没有索引? - Given two binary lists of same length, how to find all the pair of indices corresponding to ones of alternating lists without ones in between? 找出由两个 2 位数字的乘积构成的最大回文 - To find the largest palindrome made from the product of two 2-digit numbers 如何生成与已经生成的随机数不同的随机数? - How to generate random numbers different from already generated ones?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM