YouTip LogoYouTip

Python Exercise Example5

# Python2.x Python Exercise Instance 5 [![Image 3: Python 100 Examples](#) Python 100 Examples](#) **Question:** Input three integers x, y, z, please output these three numbers from smallest to largest. **Program Analysis:** We try to put the smallest number into x. First, compare x with y. If x > y, swap the values of x and y. Then compare x with z. If x > z, swap the values of x and z. This ensures x is the smallest. Program source code: ## Instance(Python 2.0+) ```python #!/usr/bin/python # -*- coding: UTF-8 -*- l = [] for i in range(3): x = int(raw_input('integer:n')) l.append(x) l.sort() print l ## Instance(Python 3.0+) ```python #!/usr/bin/python3 l = [] for i in range(3): x = int(input('integer:n')) l.append(x) l.sort() print(l) The output result of the above instance
← Python Exercise Example6Python 100 Examples β†’