Answer to Question #302307 in Python for reyadh

Question #302307

Write a Python program that takes a number from the user and prints its digits from left to right.

[Consider the input number to be an INTEGER. You are not allowed to use String indexing for solving this task]

=========================================================================

Example: if the user gives 32768, then print 3, 2, 7, 6, 8


1
Expert's answer
2022-02-24T12:18:46-0500
num = int(input("Input number: "))
array = []
while (num != 0):
    digit = num % 10  
    num = num // 10
    array.append(digit)
for i in range(len(array)-1, 0, -1):
    print(f'{array[i]}, ', end='')
print(f'{array[0]}')  #  Print last digit

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS