Answer:
The program to this question as follows:
Program:
#defining variable and assign value
odd=0
even=0
i=1
print('Input 0 after inserting all number: ') #print message
while i>0: #define loop for check inserting and add all number
i=int(input()) #input value by user end
if (i< 0): #check value is not positive
break
if ((i % 2)==0and(i>0)): #check even number condition
even=even+i #add even numbers
if ((i % 2)!=0and(i>0)): #check odd number condition
odd=odd+i #add odd numbers
print ('Sum of Even number:',even,'and','Sum of Odd number:',odd) #print value
Output:
Input 0 after inserting all number:
1
2
3
5
7
0
Sum of Even number: 2 and Sum of Odd number: 16
Explanation:
In the above python program, three variable is defined, that is "even, odd and i", in which "even and odd" variable assign value that is "0", and the variable i is used for inserting elements from user. In the next line a while loop is defined that inserts numbers in variable "i", in this loop, 3 if block is used that can be defined as follows:
- In first if block variable "i", checks that value is non-positive number if this condition is true, it will break the loop.
- In second if block this block check even number condition and add in even variable.
- In third, if block this block check odd number condition and add in odd variable.
End of the loop we use print function that prints the sum of even numbers and odd numbers.