191k views
3 votes
Write a program that prints the sum of the even numbers and the products of odd numbers on the screen

1 Answer

3 votes

Answer:

The program in Python is as follows:

n = int(input("Number of inputs: "))

total = 0; product = 1

for i in range(n):

num = int(input(": "))

if num%2 == 0:

total+=num

else:

product*=num

print("Sum of even: ",total)

print("Product of odd: ",product)

Step-by-step explanation:

This prompts the user for the number of inputs, n

n = int(input("Number of inputs: "))

This initializes sum (total) to 0 and products to 1

total = 0; product = 1

This iterates through n

for i in range(n):

This gets the inputs

num = int(input(": "))

If input is even, calculate the sum

if num%2 == 0:

total+=num

If otherwise, calculate the product

else:

product*=num

Print the required outputs

print("Sum of even: ",total)

print("Product of odd: ",product)

User Kuldeep Sakhiya
by
4.2k points