0
how to extract first and last two number in an integer
program
2 Réponses
+ 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)
+ 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