Answer
Program:
#prompt the user for a number
number = eval(input("Enter a 4-digit integer: "))
#get the individual digits from the number
onesDigit $=$ number $\% 10$
remainingNumber = number // 10
tensDigit = remainingNumber $\% 10$
remainingNumber = remainingNumber // 10
hundreadsDigit = remainingNumber $\% 10$
remainingNumber = remainingNumber // 10
thousandsDigit = remainingNumber \% 10
# Display integer in reverse order
print( thousandsDigit)
print( hundreadsDigit)
print( tensDigit)
print( onesDigit)
Work Step by Step
Step 1 of 3:
Program Plan:
Create a python file with name 2_13PE.PY. In the file,
- Get input from user. It is the a 4-digit number.
- Get the individual digits from the number using integer division (//) and remainder (\%) operators.
- Display the individual digits in reverse order.
Step 2 of 3:
Program:
#prompt the user for a number
number = eval(input("Enter a 4-digit integer: "))
#get the individual digits from the number
onesDigit $=$ number $\% 10$
remainingNumber = number // 10
tensDigit = remainingNumber $\% 10$
remainingNumber = remainingNumber // 10
hundreadsDigit = remainingNumber $\% 10$
remainingNumber = remainingNumber // 10
thousandsDigit = remainingNumber \% 10
# Display integer in reverse order
print( thousandsDigit)
print( hundreadsDigit)
print( tensDigit)
print( onesDigit)
Sample Output:
Enter a 4-digit integer: 3125
3
1
2
5