Python Exercise Example 5
Title: Enter three integers x, y, z, please put three numbers from small to big output.
Program analysis: We find a way to put the smallest number x, the first x and y are compared, if x> y then the x and y values are exchanged, and then use the x and z are compared, if x> z x and z values will be exchanged, so make x minimum.
Source Code:
#!/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
The above example output is:
integer: 8 integer: 5 integer: 6 [5, 6, 8]