-3

So, I want to find a way to make sure an int is exactly 18 digits long, in Python, and give different responses depending on whether it is or isn't. So, if, say, 336819654318227461 was entered, it would respond by saying "Yes, that's 18 digits!" or whatever else, but if, say, 15 was entered, it would say something like "No, that's not 18 digits!"

It's for a bot I'm making on Discord, where, if it is 18 digits, it'll try to kick a person based off their ID, but, if it isn't, it'll just say that it's not a real person.

Kaysom
  • 19

3 Answers3

1

maybe you could just do

len(str(336819654318227461))
Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
JeanRibes
  • 131
  • 1
  • 3
0
>>> personId = 12385412
>>> is18 = len(str(personId)) == 18
>>> is18
False
>>> personId = 123456781234567890
>>> is18 = len(str(personId)) == 18
>>> is18
True

One.Punch.Leon
  • 602
  • 3
  • 10
  • 2
    Please add an explanation with your code, so people can understand how it is behaving and how it fixes the problem. – Kevin Jan 04 '20 at 15:17
0

Is this what you are looking for:

sint= str(336819654318227461)
if len(sint)==18:
    print("Yes, that's 18 digits!")
else:
    print("No, that's not 18 digits!")
Vaibhav Jadhav
  • 2,020
  • 1
  • 7
  • 20