0

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. 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!

Patrick Parker
  • 4,863
  • 4
  • 19
  • 51
  • Welcome to Stack Overflow! You have tagged this question with `Java`, but it doesn't seem to be related to `Java`. If it isn't, please [edit] your question to remove the java tag, and if it is please edit to explain how this is related to java – GBlodgett Feb 01 '19 at 02:52
  • 1
    Can you edit the post and include your attempt? – Sohaib Farooqi Feb 01 '19 at 02:54

1 Answers1

1

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
iz_
  • 15,923
  • 3
  • 25
  • 40