Last Digit and Sign
Python
Easy
2 views
Problem Description
Read one integer n. Output two things: last digit of |n| and the sign as NEG, ZERO, or POS.
Input Format
One integer n.
Output Format
One line: lastDigit sign.
Official Solution
import sys
s=sys.stdin.read().strip()
if not s: sys.exit(0)
n=int(s)
last=abs(n)%10
if n<0: sign='NEG'
elif n>0: sign='POS'
else: sign='ZERO'
sys.stdout.write(f"{last} {sign}")
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!