2018年1月8日 星期一

Python: Count the number 4 in a given list

Python: Count the number 4 in a given list

Python Basic: Exercise-22 with Solution

Write a Python program to count the number 4 in a given list.
Sample Solution:-
def list_count_4(nums):
  count = 0  
  for num in nums:
    if num == 4:
      count = count + 1
  return count

print(list_count_4([1, 4, 6, 7, 4, 4]))
print(list_count_4([1, 4, 6, 4, 4, 7, 4]))
============ RESTART: F:/Python_APSC/py-ex-basic-22.py =============
3
4
>>> 

沒有留言:

張貼留言

RFID TI 培訓影片系列

RFID TI 培訓影片系列  https://www.ti.com/zh-tw/video/series/rfid.html 培訓影片系列 RFID 隨著創新技術日益發展,RFID 和 RF 術語越來越容易讓人混淆。本訓練系列詳細介紹了使用案例、權衡技術優缺點,讓您清楚知道該選...