list of digit with mathematics operation (loop)
context is, i want to split all number's digit like list, string function/method with loop and math operator solution is: 1) let's say we want to separate this number 123 with % operator by 10. like this, we will get last digit of number >>> x = 123 >>> a = x % 10 (get 3) 2) Divide the number you want to split by 10 to get only integers (// operator) >>> x = x // 10 (get 2) 3) bring the numbet from step 2 back to step 1 >>> b = x % 10 (12 % 10 = 2) and repeat the loop my code: n = int(input("input number: ")) remain = n digit = 0 result = ' ' while remain != 0: degit = remain % 10 if result == ' ': result = str(digit) else: result = str(digit) + ', ' + result remain = remain // 10 print(f"list of digit: {result}") input >>> 5678 #expected output list of digit: 5, 6, 7, 8 #my output list of digit: 0, 0, 0, 0 question is why my output is 0, 0, 0, 0. can someone correct my code please? i have no idea why ...