I want to reverse a number but I get this error:
"TypeError: 'type' object is not subscriptable"
I would be grateful if you could correct my code.here is my code:
number=input("enter your number ")
num=int(number)
count=0
list1=[]
while(num!=0):
list1.append(num%10)
num=num//10
count=count+1
print(list1[::-1])
k=len(list1)
after=0
for h in range(k):
after+=int(list[h])*(10**h)
h=-1
print(after)
You can do it easily using list's (create, reverse, join):
or just, much easier: