Answer to Question #242189 in Python for Ankita

Question #242189

The media company "GlobalAd" has received a

batch of advertisements from different product

brands. The batch of advertisements is a

numeric value where each digit represents the

number of advertisements the media company

has received from different product brands.

Since the company banners permit only even

numbers of advertisements to be displayed, the

media company needs to know the total

number of advertisements it will be able to

display from the given batch.

Write an algorithm to calculate the total

number of advertisements that will be

displayed from the batch.

Input

The input consists of an integer batch,

representing the batch of advertisements

Output

Print an integer representing the total number

of advertisements that will be displayed by the

media company

Constraints

0 < batchs 109


1
Expert's answer
2021-09-25T10:04:27-0400
def numAdsToDisplay(batch):
    res = 0
    while batch > 0:
        n = batch % 10
        batch //= 10
        if n % 2 == 0 and n != 0:
            res += 1


    return res

def main():
    line = input()
    num = numAdsToDisplay(int(line))
    print(f'The company should show {num} advertisements')

main()

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS