Q:

How can you sum these outputs in Python?

I made this code about a number and it's power. It will ask a number and it's power and show the output like a horizontal list.. Like 
Number = 2
Power = 3.... then output will be like=
    1
    2
    4
Number and power can be +/-.
But I want to sum those numbers like Sum = 7 after it shows 
1
2
4
I have no idea how to do it after the output. I am new to programming maybe that's why can't figure out this problem.
Here is the code in Python :
A =float(input("Number:")) 
B =float(input("Power:"))
print("Result of Powers:")
i = 0
while i < B:
    print(A**i)
    i = i + 1
while i >= B:
    print(A**i)
    i = i - 1

A:

You can create another variable to store the sum
and to print values on the same line use end=" " argument in the print function
a = float(input("Number:")) 
b = int(input("Power:"))
sum = 0.0

i = 0

while b < 0:
    ans = a**i
    i = i - 1
    print(ans, end=" ")
    sum = sum + ans
    b += 1

while  b >= 0:
    ans = a**i
    i = i + 1
    print(ans, end=" ")
    sum = sum + ans
    b -= 1

print("\nSum = " + str(sum))

