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]

>>> 


沒有留言:

張貼留言

113 學年度第 1 學期 RFID應用課程 Arduino程式

113 學年度第 1 學期 RFID應用課程 Arduino程式 https://www.mediafire.com/file/zr0h0p3iosq12jw/MFRC522+(2).7z/file 內含修改過後的 MFRC522 程式庫 (原程式有錯誤) //定義MFRC522...