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

極客小將

您現在的位置是:首頁 » python編程資訊

資訊內容

python怎么輸入三個數輸出最大的值

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

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

FiZ少兒編程網-https://www.pxcodes.com

本教程操作環境:windows7系統、Python3、Dell G3電腦。FiZ少兒編程網-https://www.pxcodes.com

輸入三個數,輸出三個數中的**大數FiZ少兒編程網-https://www.pxcodes.com

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

相關函數說明FiZ少兒編程網-https://www.pxcodes.com

Python3.x 中 input() 函數接受一個標準輸入數據,返回為 string 類型。FiZ少兒編程網-https://www.pxcodes.com

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

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

【相關推薦:Python3視頻教程 】

以上就是python怎么輸入三個數輸出**大的值的詳細內容,更多請關注少兒編程網其它相關文章!FiZ少兒編程網-https://www.pxcodes.com

預約試聽課

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

主站蜘蛛池模板: 宁波市| 清流县| 舟曲县| 加查县| 乌鲁木齐县| 榆中县| 于都县| 南雄市| 昌乐县| 丰都县| 大同县| 昔阳县| 威宁| 措勤县| 嘉义县| 景泰县| 玛纳斯县| 江安县| 丰顺县| 兴宁市| 武陟县| 察雅县| 松溪县| 彭山县| 鄂托克前旗| 晋江市| 娄底市| 镇原县| 出国| 文昌市| 通许县| 阳新县| 界首市| 广昌县| 瓦房店市| 本溪市| 铜川市| 乌拉特前旗| 繁昌县| 民权县| 灌南县|