Posted by: prankster February 6, 2013
how to?
Login in to Rate this Post:     0       ?        
N = int(input("N: "))
i=1
Sum=0

while i <= N:
    
    if i%2==0:   
          if (i !=1)
               print("-")                                          #If i is even

           print(i)
           
 
           Sum=Sum-i
    else:    
          if (i !=1) 
               print("+")                                               #if i is odd
           print(i)
           Sum=Sum+i
    i=i+1
    
print("=", Sum)




Last edited: 06-Feb-13 03:56 PM
Read Full Discussion Thread for this article