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):
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: 45Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started