国产日韩欧美一区二区三区综合,日本黄色免费在线,国产精品麻豆欧美日韩ww,色综合狠狠操

極客小將

您現(xiàn)在的位置是:首頁 » python編程資訊

資訊內(nèi)容

python怎么輸入三個數(shù)輸出最大的值

極客小將2021-04-15-
簡介方法:首先使用input()函數(shù)接收從鍵盤輸入的三個數(shù);然后使用float()或int()函數(shù)將接收的三個值統(tǒng)一轉(zhuǎn)換為浮點數(shù)或者整數(shù);接著使用“ifelse”語句比較三個數(shù)的大小,獲得最大數(shù);最后使用print()函數(shù)將最大數(shù)輸出即可。本教程操作環(huán)境:windows7系統(tǒng)、Python3、DellG

方法:首先使用input()函數(shù)接收從鍵盤輸入的三個數(shù);然后使用float()或int()函數(shù)將接收的三個值統(tǒng)一轉(zhuǎn)換為浮點數(shù)或者整數(shù);接著使用“if else”語句比較三個數(shù)的大小,獲得**大數(shù);**后使用print()函數(shù)將**大數(shù)輸出即可。FiZ少兒編程網(wǎng)-https://www.pxcodes.com

FiZ少兒編程網(wǎng)-https://www.pxcodes.com

本教程操作環(huán)境:windows7系統(tǒng)、Python3、Dell G3電腦。FiZ少兒編程網(wǎng)-https://www.pxcodes.com

輸入三個數(shù),輸出三個數(shù)中的**大數(shù)FiZ少兒編程網(wǎng)-https://www.pxcodes.com

# 第一種寫法: num1 = float(input('請輸入第一個數(shù):')) num2 = float(input('請輸入第二個數(shù):')) num3 = float(input('請輸入第三個數(shù):')) if num1 < num3 and num2 < num3: big_num = num3 elif num1 < num2 and num3 < num2: big_num = num2 else: big_num = num1 print('三個數(shù)中**大數(shù)為:%s' % big_num) # 第二種寫法(工作量會指數(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) # 第三種寫法(**簡寫法): num1 = float(input('請輸入第一個數(shù):')) num2 = float(input('請輸入第二個數(shù):')) num3 = float(input('請輸入第三個數(shù):')) max_num = num1 # 先假設(shè)num1**大 if max_num < num2: max_num = num2 if max_num < num3: max_num = num3 print('**大數(shù)是:%f' % max_num)

相關(guān)函數(shù)說明FiZ少兒編程網(wǎng)-https://www.pxcodes.com

Python3.x 中 input() 函數(shù)接受一個標(biāo)準(zhǔn)輸入數(shù)據(jù),返回為 string 類型。FiZ少兒編程網(wǎng)-https://www.pxcodes.com

int() 函數(shù)用于將一個字符串或數(shù)字轉(zhuǎn)換為整型。FiZ少兒編程網(wǎng)-https://www.pxcodes.com

float() 函數(shù)用于將整數(shù)和字符串轉(zhuǎn)換成浮點數(shù)。FiZ少兒編程網(wǎng)-https://www.pxcodes.com

【相關(guān)推薦:Python3視頻教程 】

以上就是python怎么輸入三個數(shù)輸出**大的值的詳細(xì)內(nèi)容,更多請關(guān)注少兒編程網(wǎng)其它相關(guān)文章!FiZ少兒編程網(wǎng)-https://www.pxcodes.com

預(yù)約試聽課

已有385人預(yù)約都是免費的,你也試試吧...

主站蜘蛛池模板: 海阳市| 安化县| 广宁县| 淄博市| 丽水市| 赣州市| 大港区| 西青区| 睢宁县| 陈巴尔虎旗| 临城县| 玉屏| 白山市| 陇南市| 白水县| 阳朔县| 安宁市| 新乐市| 五常市| 巩义市| 绵竹市| 偏关县| 如皋市| 仪征市| 丽水市| 宁河县| 香港 | 鄂托克前旗| 深州市| 安庆市| 二连浩特市| 景泰县| 兴城市| 江城| 磐安县| 辰溪县| 绩溪县| 剑河县| 新安县| 宜宾县| 安顺市|