python 判斷三個(gè)數(shù)字中的最大值實(shí)例代碼
python 判斷三個(gè)數(shù)字中的最大值,具體代碼如下所示:
#判斷三個(gè)數(shù)中最大值
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之三目運(yùn)算符找出三個(gè)數(shù)的最大值
Python
先寫比較兩個(gè)數(shù)大小的
a = 1 b = 2 max_ = a if a > b else b print(max_)
三個(gè)數(shù)比較
num1 = int(input("輸入第一個(gè)數(shù):"))
num2 = int(input("輸入第二個(gè)數(shù):"))
num3 = int(input("輸入第三個(gè)數(shù):"))
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;
}
總結(jié)
以上所述是小編給大家介紹的python 判斷三個(gè)數(shù)字中的最大值,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
如果你覺得本文對(duì)你有幫助,歡迎轉(zhuǎn)載,煩請(qǐng)注明出處,謝謝!
相關(guān)文章
python判斷文件夾內(nèi)是否存在指定后綴文件的實(shí)例
今天小編就為大家分享一篇python判斷文件夾內(nèi)是否存在指定后綴文件的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2019-06-06
python讀取json數(shù)據(jù)還原表格批量轉(zhuǎn)換成html
這篇文章主要介紹了python讀取json數(shù)據(jù)還原表格批量轉(zhuǎn)換成html,由于需要對(duì)ocr識(shí)別系統(tǒng)的表格識(shí)別結(jié)果做驗(yàn)證,通過返回的json文件結(jié)果對(duì)比比較麻煩,故需要將json文件里面的識(shí)別結(jié)果還原為表格做驗(yàn)證,下面詳細(xì)內(nèi)容需要的小伙伴可以參考一下2022-03-03
Python爬蟲實(shí)戰(zhàn)演練之采集糗事百科段子數(shù)據(jù)
讀萬卷書不如行萬里路,只學(xué)書上的理論是遠(yuǎn)遠(yuǎn)不夠的,只有在實(shí)戰(zhàn)中才能獲得能力的提升,本篇文章手把手帶你用Python采集糗事百科段子的數(shù)據(jù),大家可以在過程中查缺補(bǔ)漏,提升水平2021-10-10
如何讓利用Python+AI使靜態(tài)圖片動(dòng)起來
這篇文章主要介紹了如何讓利用Python+AI使靜態(tài)圖片動(dòng)起來,基于的GAN生成對(duì)抗網(wǎng)絡(luò)圍繞主題實(shí)現(xiàn)靜態(tài)圖片動(dòng)起來的效果。具有一定的參考價(jià)值,需要的小伙伴可以參考一下2022-06-06
Python paramiko模塊使用解析(實(shí)現(xiàn)ssh)
這篇文章主要介紹了Python paramiko模塊使用解析(實(shí)現(xiàn)ssh),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-08-08

