题目五:输入三个整数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)
继续阅读与本文标签相同的文章
上一篇 :
网络间谍组织越来越多地利用路由器进行攻击
下一篇 :
平安 AI 护航,是时候来次教育升级了
-
每分钟进出车辆2.5台 智能立体车库解锁停车难
2026-05-19栏目: 教程
-
一文了解机器学习必学10大算法
2026-05-19栏目: 教程
-
开一家线上外卖门店选址要注意哪些因素?
2026-05-19栏目: 教程
-
信院人的APP,你get到了吗?
2026-05-19栏目: 教程
-
对话FILA姚伟雄:安踏赋予独立性,未来坚持做直营
2026-05-19栏目: 教程
