YouTip LogoYouTip

Python Exercise Example29

# Python2.x Python Exercise Instance 29 [![Image 3: Python 100 Examples](#) Python 100 Examples](#) **Question:** Given a positive integer with no more than 5 digits, requirements: 1. Find how many digits it has, 2. Print the digits in reverse order. **Program Analysis:** Learn to decompose each digit. Program source code: ## Instance(Python2.x) ```python #!/usr/bin/python # -*- coding: UTF-8 -*- x = int(raw_input("Please enter a number:n")) a = x / 10000 b = x % 10000 / 1000 c = x % 1000 / 100 d = x % 100 / 10 e = x % 10 if a != 0: print "5 Number of digits:",e,d,c,b,a elif b != 0: print "4
← Python Exercise Example30Python Exercise Example28 β†’