2018年1月11日 星期四

Python: Find the maximum and minimum numbers from a sequence of numbers

Python: Find the maximum and minimum numbers from a sequence of numbers

Python Basic: Exercise-148 with Solution

Write a Python function to find the maximum and minimum numbers from a sequence of numbers.
Note: Do not use built-in functions.
Sample Solution :-
def max_min(data):
  l = data[0]
  s = data[0]
  for num in data:
    if num> l:
      l = num
    elif num< s:
        s = num
  return l, s
print(max_min([0, 10, 15, 40, -5, 42, 17, 28, 75]))

========= RESTART: F:/Python_APSC/py-ex-basic-148.py ===========
(75, -5)
>>> 

沒有留言:

張貼留言

結合桌面視窗介面 (GUI)、雲端資料庫與社群通訊推播的自動化氣象監控系統

視窗介面 (GUI)、雲端資料庫與社群通訊推播的自動化氣象監控系統 這份 gui_app_timer.py 程式是一個 結合桌面視窗介面 (GUI)、雲端資料庫與社群通訊推播的自動化氣象監控系統 。 整體架構採用 事件驅動 (Event-Driven) 與 多執行緒非同步設計...