Q:

How to perform digitsum for a negative integer input until a single digit is obtained?

My code:
def add_digits():
    num=int(input("Enter  "))
    return (num - 1) % 9 + 1 if num > 0 else 0

print(add_digits())

How to make this work for negative input? Please do help. Thanks in advance for your time and help.

A:

First, you should have your add_digits function take in the value as a parameter rather than getting it from the user; that'll make it easier to build on it:
def add_digits(num: int) -> int:
    return (num - 1) % 9 + 1 if num > 0 else 0

print(add_digits(int(input("Enter "))))

Now you have a much simpler problem to solve: how do we make sure that when this function gets passed a negative number, it returns the negative of the result of the corresponding positive number?  That's very easy to express as a simple recursive call at the beginning:
def add_digits(num: int) -> int:
    if num < 0:
        return -add_digits(-num)
    return (num - 1) % 9 + 1 if num > 0 else 0

assert add_digits(123456) == 3    # ok
assert add_digits(-123456) == -3  # ok

