Posted by: comingsoon February 6, 2013
Login in to Rate this Post:
0
?
I try this but total is not right.
also 1-2+3-4 doesn't work while user give odd number.
N = int(input("N: "))
i=1
x=2
Sum1=0
Sum2=0
while i <= N and x <=N:
print("+", i, "-", x, end=' ')
i= i+2
x= x+2
Sum1=Sum1+i
Sum2=Sum2+x
print("=", Sum1-Sum2)
Result
>>>
N: 4
+ 1 - 2 + 3 - 4 = -2
>>> ================================ RESTART ================================
>>>
N: 5
+ 1 - 2 + 3 - 4 = -2
>>>
Here it prints only 4, should print upto 5(user's given value) and total is not valid.
also 1-2+3-4 doesn't work while user give odd number.
N = int(input("N: "))
i=1
x=2
Sum1=0
Sum2=0
while i <= N and x <=N:
print("+", i, "-", x, end=' ')
i= i+2
x= x+2
Sum1=Sum1+i
Sum2=Sum2+x
print("=", Sum1-Sum2)
Result
>>>
N: 4
+ 1 - 2 + 3 - 4 = -2
>>> ================================ RESTART ================================
>>>
N: 5
+ 1 - 2 + 3 - 4 = -2
>>>
Here it prints only 4, should print upto 5(user's given value) and total is not valid.
Last edited: 06-Feb-13 12:50 PM