• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

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

python 搞代码 4年前 (2022-01-08) 71次浏览 已收录 0个评论

这篇文章主要介绍了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之三目运算来源gao($daima.com搞@代@#码(网符找出三个数的最大值

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 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 判断三个数字中的最大值实例代码的详细内容,更多请关注gaodaima搞代码网其它相关文章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:python 判断三个数字中的最大值实例代码

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址