Python100例--005

题目:输入三个整数x,y,z,请把这三个数由小到大输出
方法一:

# -*- coding:utf-8 -*-
# l = []
# for i in range(3):
#     x = int(raw_input("integer:"))
#     l.append(x)
# l.sort()
# print l

方法二:

# -*- coding:utf-8 -*-
# x = int(raw_input("x:"))
# y = int(raw_input("y:"))
# z = int(raw_input("z:"))
# a = {"x":x,"y":y,"z":z}
# for i in sorted(a,key=a.get):
#     print i,a[i]

方法三:

# -*- coding:utf-8 -*-
l = []
for i in range(3):
    x = int(raw_input("integet:"))
    l.append(x)
n = len(l)
for j in range(0,n):
    for k in range(j+1,n):
        if(l[j] >= l[k]):
            tmp = l[j]
            l[j] = l[k]
            l[k] = tmp
print l

你可能感兴趣的:(Python100例--005)