The number of zeros. Given a series of N numbers where the first number in the input specifies N, followed by N integers, count how many of these integers are zero and print the count.
Note that you need to count the number of integers that are equal to zero, not the number of zero digits within the numbers.
|
N = int(input()) count_zeros = 0 for _ in range(N): if int(input()) == 0: count_zeros += 1 print(count_zeros) |
- Reading the Number of Integers:
- The
input()
function reads a line of text from the user.
- The
int()
function converts this input to an integer and stores it in the variable N
.
- Initialize the Zero Count:
- A variable
count_zeros
is initialized to 0. This will be used to count the number of integers that are equal to zero.
- Reading and Counting Zeros:
for _ in range(N):
if int(input()) == 0:
count_zeros += 1
- A
for
loop runs N
times, as indicated by range(N)
.
- Each iteration reads a number from the user using
input()
, converts it to an integer with int()
, and checks if it is zero.
- If the number is zero,
count_zeros
is incremented by 1.
- Printing the Zero Count:
- Finally, the
print()
function outputs the value of count_zeros
.