1071.Sum of Consecutive odd Number-(i) in python
This is the solution of the problem in python:
X=int(input())
Y=int(input())
total=0
if(X%2==0 and Y>X):
X=X+1
for i in range(X,Y+1,2):
total=total+i
print(total)
elif(X%2!=0 and Y>X):
for i in range(X,Y+1,2):
total=total+i
print(total)
elif(X%2==0 and X>Y):
X=X-1
for i in range(X,Y-1,-2):
total=total+i
print(total)
elif(X%2!=0 and X>Y):
for i in range(X,Y-1,-2):
total=total+i
print(total)
No comments