-2
所以我试图写一个程序,它的正,负数和再一次输入0结束显示它们,追踪我的代码,它似乎是在一个连续循环
pos1=0
neg1=0
all1=0
flt1=float(raw_input("enter a non-zero floating point number (decimals): "))
while(flt1!=0.0):
if (flt1 < 0.0):
neg1=neg1+flt1
all1=all1+flt1
elif(flt1 > 0.0):
pos1=pos1+flt1
all1+all1+flt1
print "the sum of all numbers entered is ",all1,"the sum of all positive numbers are ",pos1,
print "and the sum of all negitive numbers are ",neg1,
我的问题当我真正追踪它时(如果我说5.0并跟踪它),我发现它被卡在代码的“elif”部分,并且实际上并没有回来询问另一个数字。我被困在试图找出我需要做什么来回来并要求另一个非零数字。我的目标是让用户不断输入数字,直到他/她输入0,然后将所有负数加起来并显示出来,然后对正数执行相同的操作,然后显示所有的总和(negs和pos)远输入0的作品,但没有别的
编辑:在ELIF环
你的意思是'全部为1 =全部为1 + flt1',你*永远不会改变'flt1' *。 – jonrsharpe 2014-10-28 16:34:31
你在'elif'块中有坏缩进! – Kasramvd 2014-10-28 16:34:37