Find answers to your questions faster and easier with IDNLearn.com. Ask your questions and receive comprehensive and trustworthy answers from our experienced community of professionals.

Write a program that prints the sum of the even numbers and the products of odd numbers on the screen

Sagot :

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)

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)

Thank you for joining our conversation. Don't hesitate to return anytime to find answers to your questions. Let's continue sharing knowledge and experiences! IDNLearn.com is your source for precise answers. Thank you for visiting, and we look forward to helping you again soon.