Computer Science, asked by harisellahi888, 3 months ago

Write a program that reads a set of integers from user, and then prints the sum of
the even and odd integers.

Answers

Answered by vaibhavdantkale65
1

Explanation:

bsnsnsnnzbznzmsskskkamaizz

Answered by stalwartajk
0

Answer:

There is a Python program that reads a set of integers from the user, and then prints the sum of even and odd integers separately

Explanation:

Here's a Python program that reads a set of integers from the user, and then prints the sum of even and odd integers separately:

# initialize even and odd sum to zero

even_sum = 0

odd_sum = 0

# read integers from user input

num_list = list(map(int, input("Enter integers separated by spaces: ").split()))

# iterate through each integer in the list

for num in num_list:

   # check if the integer is even or odd

   if num % 2 == 0:

       even_sum += num

   else:

       odd_sum += num

# print the sum of even and odd integers

print("Sum of even integers:", even_sum)

print("Sum of odd integers:", odd_sum)

  • We initialize two variables even_sum and odd_sum to zero.
  • We use the input() function to read a line of user input, which should consist of integers separated by spaces. We use the split() method to split this input string into a list of individual integers, and then use the map() function to convert each element of the list from a string to an integer.
  • We use a for loop to iterate through each integer in the list.
  • Inside the loop, we check if the integer is even or odd using the modulus operator (%). If the remainder of num divided by 2 is zero, then num is even, so we add it to even_sum. Otherwise, num is odd, so we add it to odd_sum.
  • Finally, we print the sum of even integers and odd integers separately using the print() function.

Learn more about Python : https://brainly.in/question/16086632

Learn more about integers: https://brainly.in/question/54141444

#SPJ6

Similar questions