Python Problem About List, Loop

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

What error are you getting?

1 Like

ı dont get an error, ı just want to the program to work for larger numbers as well and i don’t want to write it by hand like this

You mentioned it’s crashing. There should be some error displayed when crashing.

Otherwise what is not working? Without knowing that it’s hard to help.

I mentioned about the last line

I don’t know what that means.

Without exactly knowing what is the problem, what is not working or what you would like to change, it is impossible to help.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.