0

how to extract first and last two number in an integer

program

15th Aug 2018, 6:01 AM
Vidhyapriya
Vidhyapriya - avatar
2 Answers
+ 5
I'm not sure if I understood correctly, can you be clearer? Anyway, here is my try in Python: n = input() if len(n) < 2: print("integer has less than two digits") else: first = n[0] last = n[-1] print(first, last)
15th Aug 2018, 6:23 AM
Eduardo Petry
Eduardo Petry - avatar
+ 2
You can do it in many way... The more simple is: - Transform your number in string - Check if this string size is least 3 - Get your chars
15th Aug 2018, 6:40 AM
KrOW
KrOW - avatar