欢迎来到代码驿站!

Python代码

当前位置:首页 > 软件编程 > Python代码

python 判断三个数字中的最大值实例代码

时间:2021-01-21 10:52:04|栏目:Python代码|点击:

python 判断三个数字中的最大值,具体代码如下所示:

#判断三个数中最大值
n1= int(input('please enter the firest number:'))
n2 = int(input('please enter the second number:'))
n3 = int(input('please enter the third number:'))
max_num = 0
if n1 > n2:
 max_num = n1
 if n1 > n3:
  max_num = n1
 else:
  max_num = n3
else:
 max_num = n2
 if n2 > n3:
  max_num = n2
 else:
  max_num = n3
print('the max_num is:%d'%max_num)
'''
if n1>n2:
 max_num = n1
 if max_num > n3:
  print('the max_num is n1')
 else:
  print('the max_num is n3')
else:
 max_num = n2
 if max_num > n3:
  print('the max_num is n2')
 else:
  print('the max_num is n3')
'''

PS:python之三目运算符找出三个数的最大值

Python

先写比较两个数大小的

a = 1
b = 2
max_ = a if a > b else b
print(max_)

三个数比较

num1 = int(input("输入第一个数:"))
num2 = int(input("输入第二个数:"))
num3 = int(input("输入第三个数:"))
max_ = (num1 if num1 > num2 else num2) if(num1 if num1 > num2 else num2) > num3 else num3
print(max_)

Java帝国

package com.zzti.edu;

import java.util.Scanner;

/**
 * @Classname threeEye
 * @Description TODO
 * @Author jdq8576
 * @Date 2019/3/2 14:28
 * @Version 1.0
 **/
public class threeEye {
 public static void main(String[] args){
  int a;
  int b;
  int c;
  Scanner scanner = new Scanner(System.in);
  a = scanner.nextInt();
  b = scanner.nextInt();
  c = scanner.nextInt();
  scanner.close();
  System.out.println((a>b?a:b)>c?(a>b?a:b):c);
 }
}

C++

#include<iostream>
using namespace std;
int main(){
 int a,b,c;
 cin>>a>>b>>c;
 int max = (a>b?a:b)>c?(a>b?a:b):c;
 cout<<max<<endl;
 return 0;
}

总结

上一篇:详解Python中heapq模块的用法

栏    目:Python代码

下一篇:Python3爬虫里关于Splash负载均衡配置详解

本文标题:python 判断三个数字中的最大值实例代码

本文地址:http://www.codeinn.net/misctech/48660.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有