CBSE Class 11 Computer Science Question 156 of 173

Data Handling — Question 8

Back to all questions
8
Question

Question 8

Try writing program (similar to previous one) for three digit number i.e., if you input 123, the program should print 321.

Solution
x = int(input("Enter a three digit number: "))

d1 = x % 10
x //= 10
d2 = x % 10
x //= 10
d3 = x % 10
y = d1 * 100 + d2 * 10 + d3

print("Reversed Number:", y)
Output
Enter a three digit number: 123
Reversed Number: 321
Answer