题目五:输入三个整数x,y,z,请把这三个数由小到大输出。
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
""" 题目五:输入三个整数x,y,z,请把这三个数由小到大输出。"""
__author__ = 'Fan Lijun'
one = eval(input('请输入三个数:'))
two = eval(input('请输入三个数:'))
three = eval(input('请输入三个数:'))
#方法一:使用内置排序函数
lst = [one, two, three]
print(lst.sort())
#方法二:我自己写一个,锻炼一下if else
lst2 = []
#获得最小数
def minNumber(one, two, three):
if one < two:
if one < three:
lst2.append(one)
else:
lst2.append(three)
else:
if two < three:
lst2.append(two)
else:
lst2.append(three)
def maxNumber(one, two, three):
if one > two:
if one > three:
lst2.append(one)
else:
lst2.append(three)
else:
if two > three:
lst2.append(two)
else:
lst2.append(three)
minNumber(one, two, three)
maxNumber(one, two, three)
if lst2[0] == one:
if lst2[1] == two:
lst2.insert(1, three)
else:
lst2.insert(1, two)
elif lst2[0] == two:
if lst2[1] == three:
lst2.insert(1, one)
else:
lst2.insert(1, three)
else:
if lst2[1] == two:
lst2.insert(1, one)
else:
lst2.insert(1, three)
print(lst2)