python3 练习题100例 (五)
2024-08-27 19:41:54
题目五:输入三个整数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)
最新文章
- AlloyTouch与three.js 3D模型交互
- Asp.net 配置web.Config 在出错时跳转到相应页面
- (App.Current.RootVisual as PhoneApplicationFrame).Navigate(new Uri(";/MainPage.xaml";, UriKind.Relative));
- SLP的模块结构
- java重写equals方法
- LintCode Singleton
- CSocket服务器(TCP)
- 读书笔记--用Python写网络爬虫01--网络爬虫简介
- 表单验证提交——submit与button
- 云风:我所偏爱的C语言面向对象编程范式
- C# Url编码 HtmlUrl编码
- 注意使用 BTREE 复合索引各字段的 ASC/DESC 以优化 order by 查询效率
- .10-Vue源码之Watcher(1)
- Linux IO 模型
- Kotlin 接口
- Promise是什么?
- spring mvc 的上传图片是怎么实现的?
- NoSql的三大基石:CAP理论&;BASE&;最终一致性
- 以ORM的思路来从Excel文件中读取JSON数据列表
- 你如何获取浏览器URL中查询字符串中的参数?