python 三个数字比较大小,判断大小,按照大小顺序输出
1.利用条件判断语句(if-elif-else)两两比较
# 提醒用户输入三个整数,通过int()方法将str类型转换成int类型
number_one = int(input("请输入一个整数"))
number_two = int(input("请输入一个整数"))
number_three = int(input("请输入一个整数"))
# 判断第一个数字是否大于第二个数字
if number_one > number_two: # 条件成立判断第二个数字是否大于第三个数字 if number_two > number_three: print("{}>{}>{}".format(number_one, number_two, number_three)) elif number_two < number_three: if number_one > number_three: print("{}>{}>{}".format(number_one, number_three, number_two)) elif number_one < number_three: print("{}>{}>{}".format(number_three, number_one, number_two))
elif number_one < number_two: if number_one > number_three: print("{}>{}>{}".format(number_two, number_one, number_three)) elif number_one < number_three: if number_three > number_two: print("{}>{}>{}".format(number_three, number_two, number_one)) elif number_three < number_two: print("{}>{}>{}".format(number_two, number_three, number_one))
2.将三个数字添加到列表中,再通过max函数进行大小比较
# 利用列表的max()函数来比较大小
numbers = []
for i in range(3):number = int(input("请输入第{}个整数".format(i+1)))numbers.append(number)
print(numbers)
for i in range(len(numbers)):max_number = max(numbers)print("{}>".format(max_number), end="")numbers.remove(max_number)
3.利用列表的sort函数对数字进行排序并通过reverse将数字通过降序输出
# 利用sort排序来进行比较
numbers = []
for i in range(3):number = int(input("请输入第{}个整数".format(i+1)))numbers.append(number)
print(numbers)
numbers.sort(reverse=True)
print("{}>{}>{}".format(numbers[0], numbers[1], numbers[2]))
python 三个数字比较大小,判断大小,按照大小顺序输出相关推荐
- 输入a,b,c三个整数,按由大到小顺序输出。(用3个指针变量指向3个整形变量,然后用swap函数来实现互换3个整型变量的值)
/* * Copyright (c) 2012, 烟台大学计算机学院 * All rights reserved. * 作 者: 刘同宾 * 完成日期:2012 年 11 月 29 日 * 版 本 号 ...
- php正则表达式判断三个数字相等相同|判断豹子
if (preg_match('/^(?:([0-9])\1{2})+\/{1}+\d+$/', $data)) { echo "判断成功"; } 判断的结果为 判断文字加数字斜杠 ...
- 输入三个数,按照由大到小的顺序输出
void swap(int *p1,int *p2)/*实现两个数交换的函数*/ { int temp; temp=*p1; *p1=*p2; *p2=temp; } void exchange(in ...
- PYTHON#按照大小顺序输出三个数字
#按照大小顺序输出三个数字 n1 = int(input('n1 = :')) n2 = int(input('n2 = :')) n3 = int(input('n3 = ')) def swap( ...
- python中if语句求最大值_python 判断三个数字中的最大值实例代码
python 判断三个数字中的最大值,具体代码如下所示: #判断三个数中最大值 n1= int(input('please enter the firest number:')) n2 = int(i ...
- python求三个数的最大值编程_python 判断三个数字中的最大值实例代码
python 判断三个数字中的最大值,具体代码如下所示: #判断三个数中最大值 n1= int(input('please enter the firest number:')) n2 = int(i ...
- 用python输入三个整数输出最大值_python 判断三个数字中的最大值实例代码
python 判断三个数字中的最大值,具体代码如下所示: #判断三个数中最大值 n1= int(input('please enter the firest number:')) n2 = int(i ...
- c++用一级运算比较大小_Python 学习笔记:Python 中的数字和数字型运算
在 Python 数据类型知识中我们已经初步认识了几种 Python 中的数据类型,现在我们更详细的学习一下 数字型 以及 数字型运算. 我们已经知道了 Python 中的数字分为两种,分别是整数 i ...
- 输入三个数字比较大小
#define _CRT_SECURE_NO_WARNINGS 1 #include <stdio.h> //比较三个数字的大小 int main() { //输入三个数字 ...
最新文章
- OSPF:LSA Type-7 to Type-5 转发地址抑制(实验)
- 程序员面试题精选100题(31)-从尾到头输出链表[数据结构]
- Java集合篇:Map总结
- 禁用内存清理_win10电脑开机内存占用高达80%以上如何解决
- MySQL format()函数
- mysql 导入oracle 11_导入oracle11g的数据库到自己本地电脑
- 区块链 Fisco bcos 智能合约(17)-区块链的速度困境:“贵”在信任,“慢”得其所
- C++设计模式:UML工具及常用符号
- Azure云平台 GPS大数据解决方案 EventHub+Azure Databricks+Azure Cosmos DB Cassandra
- springboot优缺点
- 模拟QQ登陆,并按QQ号查询QQ基本资料
- 【杂谈】360极速浏览器本地收藏夹的文件在哪里?
- 手把手 教你如何做网线接头
- 安装Ubuntu后必须要做的几件事 一 --基础应用篇
- 腾讯云开发环境部署系列教程一 【申请免费的腾讯云主机】
- python2 中文字符编码转换
- 路由传参的几种方式 亲测有效!!!!
- 相容/不相容非齐次线性方程组的最小二乘解与最佳最小二乘解
- esp8266+arduino IDE+阿里云IOT+萤石云=远程视频遥控车(一)
- 运维思索:自动化运维体系如何入手