Hi, what can i do to keep my program from crashing?
PROBLEM:
Sum of digits of x raised to n For some x^n , find the sum of its digits until there is only a one digit. The order of commandline arguments:
python3 quiz3-1.py a b =>python3 quiz3-1.py 2 5
Output : 2ˆ5 = 32 = 3 + 2 = 5
python3 quiz3-1.py 5 3
Output : 5ˆ3 = 125 = 1 + 2 + 5 = 8
There are my codes:
import sys
a=int(sys.argv[1])
b=int(sys.argv[2])
c=a**b
liste=[]
c=str(c)
c.split()
c=list(c)
for i in c:
i=int(i)
liste.append(i)
toplam=sum(liste)
t=a**b
if len(liste)==1:
print(a, "^", b, "=", t, "=", liste[0], "=", toplam)
elif len(liste)==2:
print(a, "^", b, "=", t, "=", liste[0], "+", liste[1], "+", "=", toplam)
elif len(liste)==3:
print(a, "^", b, "=", t, "=", liste[0], "+", liste[1], "+", liste[2], "=", toplam)
elif len(liste)==4:
print(a, "^", b, "=", t, "=", liste[0], "+", liste[1], "+", liste[2], "+", liste[3], "=", toplam)
else:
print("program crashed please enter smaller numbers")
how can i fix
thanks