2018年1月9日 星期二

Python: Sort three integers without using conditional statements and loops

Python: Sort three integers without using conditional statements and loops

Python Basic: Exercise-69 with Solution
Write a Python program to sort three integers without using conditional statements and loops.
Sample Solution:-
x = int(input("Input first number: "))
y = int(input("Input second number: "))
z = int(input("Input third number: "))
a1 = min(x, y, z)
a3 = max(x, y, z)
a2 = (x + y + z) - a1 - a3
print("Numbers in sorted order: ", a1, a2, a3)

========== RESTART: F:\Python_APSC\py-ex-basic-69.py =========
Input first number: 9
Input second number: 45
Input third number: 98
Numbers in sorted order:  9 45 98
>>> 
========== RESTART: F:\Python_APSC\py-ex-basic-69.py =========
Input first number: 89
Input second number: 5
Input third number: 45
Numbers in sorted order:  5 45 89
>>> 



沒有留言:

張貼留言

Node-Red --> MQTT --> Fuxa 開源碼網頁式圖控平台

Node-Red --> MQTT --> Fuxa      FUXA(一個開源的 Web HMI / SCADA 自動化監控軟體)的專案設定檔 。 這份設定檔完整定義了 HMI 監控畫面的 後端通訊(MQTT 連線、點位標籤) 與 前端網頁圖形介面(SVG 畫布...