Ask Question

Write a program that inputs a non negative integer, separates the integer into its digits and prints them separated by tabs each. For example, if the user types in 42339, the program should print:42339

+5
Answers (1)
  1. 7 March, 13:34
    0
    tab = ""

    number = int (input ("Enter a nonnegative integer: "))

    while number:

    digit = number % 10

    if len (str (number)) ! = 1:

    tab + = str (digit) + "/t"

    else:

    tab + = str (digit)

    number / / = 10

    print (tab[::-1])

    Explanation:

    * The code is in Python

    - Initialize an empty string to hold the digits

    - Ask the user for the input

    Inside the loop:

    - Get the digits of the number. If the length of the number is not 1 (If it is not the first digit), put a tab between the digits. Otherwise, just put the number (This will get the numbers from the last digit. If number is 123, it gets 3 first, then 2, then 1)

    - Print the string in reverse order
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Write a program that inputs a non negative integer, separates the integer into its digits and prints them separated by tabs each. For ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers