Create a Python script which will accept two positive integers where the first number would be the start of a range and the second number would be the end of a range. Then the application will determine the sum of all EVEN numbers and sum of all ODD numbers from the given range.
Sample Output:
Start of a Range: 5
End of a Range: 10
Sum of Even nos. is 24
Sum of Odd nos. is 21
I need the code to have an output stated above.
Start = int(input("Enter Start of the Range: "))
End = int(input("Enter End of the Range : "))
SumEven=0
SumOdd=0
for r in range(Start,End+1):
if(r%2==0): SumEven=SumEven+r
if(r%2==1): SumOdd =SumOdd+r
print("Sum of Even Numbers: ",SumEven)
print("Sum of Odd Numbers: ",SumOdd)
Comments
Leave a comment