Posted by: prankster February 6, 2013
how to?
Login in to Rate this Post:     0       ?        
did you put indentation for print(i)   
print("-")                                          

           print(i)

I went to http://mathcs.holycross.edu/~kwalsh/python/
and tried following code, 
N = 5
i=1
Sum=0
 
while i <= N:
    
    if i%2==0:   
          if (i !=1):
              print "-"                                         
          print i
           
 
          Sum=Sum-i
    else:    
          if (i !=1): 
               print "+"                                             
          print i
          Sum=Sum+i
    i=i+1
    
print "=" + str(Sum) 


The output was, 
1
-
2
+
3
-
4
+
5
=3
 
Read Full Discussion Thread for this article