Posted by: prankster February 6, 2013
Login in to Rate this Post:
0
?
I'm not familiar with python either, following if should only be for print("-") and not print(i) . and i assume, end=' ' is for not adding line break.
if (i !=1)
print("-")
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)
probably that would work, pls add end = ' ' to all the print statement
if (i !=1)
print("-")
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)
probably that would work, pls add end = ' ' to all the print statement