python3 练习题100例 (五)
程序员文章站
2022-04-28 18:00:56
题目五:输入三个整数x,y,z,请把这三个数由小到大输出。 ......
题目五:输入三个整数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)