Absolute Value
Python
Easy
2 views
Problem Description
Read one integer n. Create function ab(n) and output absolute value.
Input Format
One integer n.
Output Format
One integer abs(n).
Official Solution
import sys
s=sys.stdin.read().strip()
if not s: sys.exit(0)
n=int(s)
def ab(x):
return -x if x<0 else x
sys.stdout.write(str(ab(n)))
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!