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
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<
<
總結
以上所述是小編給大家介紹的python 判斷三個數字中的最大值,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網站的支持!
如果你覺得本文對你有幫助,歡迎轉載,煩請注明出處,謝謝!
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061
微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元

