Reversing a number using list in python -
i want reverse number error:
"typeerror: 'type' object not subscriptable"
i grateful if correct code.here code:
number=input("enter 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 h in range(k): after+=int(list[h])*(10**h) h=-1 print(after)
you can using list's (create, reverse, join):
''.join(map(str, list(reversed(list(str(num)))))) or just, easier:
int(str(num)[::-1])
Comments
Post a Comment