Question: Please correct the following Python code to match the indicated output. **Do not copy other answers on Chegg, do not use the input function** Prompt:

Please correct the following Python code to match the indicated output. **Do not copy other answers on Chegg, do not use the input function**

Prompt:

Write a program that reads the input repeatedly using a for loop, and then prints the sum of the even and odd integers separately.

Input:

a) python C:\Users eda\DataProgramming\M5\assign5-7.py 12 3 4 5 10 5 9 23 40

b) python C:\Users eda\DataProgramming\M5\assign5-7.py 3 4 6 5 3 4

Output:

a) sum of even: 66 ,sum of odd: 45

b) sum of even: 14 ,sum of odd: 11

Python code:

import sys

evennumbers = 0 oddnumbers = 0

for i in range(1, len(sys.argv)): temp = int(sys.argv[i]) if temp % 2 == 0: evennumbers += temp else: oddnumbers += temp print("sum of even: "+str(evennumbers)+" ,sum of odd: "+str(oddnumbers))

Outcome (needs correction):

Please correct the following Python code to match the indicated output. **Do

sum of even: 12, sum of odd: 0 sum of even: 12 , sum of odd: 3 sum of even: 16 , sum of odd: 3 sum of even: 16 , sum of odd: 8 sum of even: 26 , sum of odd: 8 sum of even: 26 , sum of odd: 13 sum of even: 26 , sum of odd: 22 sum of even: 26 , sum of odd: 45 sum of even: 66, sum of odd: 45

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!