72.7k views
5 votes
Write an application that inputs a five digit integer (The number must be entered only as ONE input) and separates the number into its individual digits using MOD, and prints the digits separated from one another. Your code will do INPUT VALIDATION and warn the user to enter the correct number of digits and let the user run your code as many times as they want (LOOP). Submit two different versions

1 Answer

6 votes

Answer:

The programs are written in python:

Version 1:

n = int(input("Numbers: "))

for i in range(n):

num = int(input("Input integer: "))

mylist = []

while num>0:

mylist.append(num%10)

num= int(num/10)

mylist.reverse()

for i in mylist:

print(i,end=" ")

print()

Version 2:

num = int(input("Input integer: "))

while num > 0:

mylist = []

while num>0:

mylist.append(num%10)

num= int(num/10)

mylist.reverse()

for i in mylist:

print(i,end=" ")

print()

num = int(input("Input integer: "))

Step-by-step explanation:

Version 1:

This gets the number of inputs from the user, n

n = int(input("Numbers: "))

This iterates through n

for i in range(n):

For each iteration, this gets the integer input from the user, num

num = int(input("Input integer: "))

This initializes a list

mylist = []

This loop is repeated until num is 0

while num>0:

This gets the individual digit and appends it to a list

mylist.append(num%10)

This gets the other numbers

num= int(num/10)

This reverses the list

mylist.reverse()

This prints the individual digits from the list

for i in mylist:

print(i,end=" ")

Print a new line for the next integer input

print()

Version 2:

The difference in both versions are the following lines

This gets the integer input from the user

num = int(input("Input integer: "))

This loop enables the user to input as many numbers as possible. But once the user inputs 0, the program will stop

while num > 0:

Unlike version 1 where the number of inputs in known at the initial stage of the program

User Bluecricket
by
8.0k points