From 8e9e58af279ab72aed8b586af818322227f58429 Mon Sep 17 00:00:00 2001 From: Brian Juma Date: Tue, 12 Sep 2023 12:55:01 +0300 Subject: [PATCH 1/2] Add count_zeros(arr) function declaration --- jumabrian/count_zeros.py | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 jumabrian/count_zeros.py diff --git a/jumabrian/count_zeros.py b/jumabrian/count_zeros.py new file mode 100644 index 00000000..2a4eb422 --- /dev/null +++ b/jumabrian/count_zeros.py @@ -0,0 +1,9 @@ +# function takes in an array of integers A and returns the count for zeros in the array + +def count_zeros(A)-> int: + count = 0 + for num in A: + if num == 0: + count += 1 + + return 0 \ No newline at end of file From 9bd4bce468c4a5d1c1ff7977e402737bb89b39f8 Mon Sep 17 00:00:00 2001 From: Brian Juma Date: Tue, 12 Sep 2023 12:58:15 +0300 Subject: [PATCH 2/2] chore: perform function call for testing --- jumabrian/count_zeros.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/jumabrian/count_zeros.py b/jumabrian/count_zeros.py index 2a4eb422..afa4d948 100644 --- a/jumabrian/count_zeros.py +++ b/jumabrian/count_zeros.py @@ -6,4 +6,10 @@ def count_zeros(A)-> int: if num == 0: count += 1 - return 0 \ No newline at end of file + return 0 + + +# Simple function call for dry run +arr = [1, 0, 5, 6, 0, 2] +result = count_zeros(arr) # 2 +print(result) \ No newline at end of file