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]

>>> 


沒有留言:

張貼留言

2026 作業1 MQTT基本觀念

 2026 作業1MQTT基本觀念 作業  參考下面網址 https://alex9ufoexploer.blogspot.com/2025/02/1-mqtt-relay-dht22-mqtt-box-pc-mymqtt.html https://alex9ufoexploer...