2018年1月11日 星期四

Python: Get numbers divisible by fifteen from a list using an anonymous function

Python: Get numbers divisible by fifteen from a list using an anonymous function

Python Basic: Exercise-110 with Solution

Write a Python program to get numbers divisible by fifteen from a list using an anonymous function.
Sample Solution:-
num_list = [45, 55, 60, 37, 100, 105, 220]
# use anonymous function to filter
print("Numbers list :",num_list)
result = list(filter(lambda x: (x % 15 == 0), num_list))
print("Numbers divisible by 15 are",result)

=========== RESTART: F:/Python_APSC/py-ex-basic-110.py ===========
Numbers list : [45, 55, 60, 37, 100, 105, 220]
Numbers divisible by 15 are [45, 60, 105]
>>> 


print("Please input a number list : ",end='')

numList = [int(x) for x in input().split(',')]

print("Numbers list :",numList)

result = list(filter(lambda x: (x % 15 == 0), numList))


print("Numbers divisible by 15 are",result)



======== RESTART: F:/Python_APSC/py-ex-basic-110.py ===========
Please input a number list : 35,45,60,25
Numbers list : [35, 45, 60, 25]
Numbers divisible by 15 are [45, 60]

>>> 


沒有留言:

張貼留言

Node-Red --> MQTT --> Fuxa

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