我有一个作业问题,我搞不懂,有人能帮忙吗
--创建一个名为sums的函数,该函数将提示用户输入整数值(正或负)。函数应保持正值和负值的单独运行总计。应允许用户继续输入值,直到输入0停止。在
这是我得到的,但它不起作用
number = int(raw_input("Enter and a positive or negative integer: "))
def sums(number):
while (number > 0):
posnumber = int(raw_input("Enter another number or 0 to quit: " ))
number = number + posnumber
print "The positive total is", number
while (number < 0):
negnumber = int(raw_input("Enter another number or 0 to quit: " ))
number = number + negnumber
print "The negative total is", number
它只是在第一次迭代下运行循环,我不知道该怎么做才能纠正它
因为它们是独立的while循环-第一个执行,第二个执行。你根本不想那样。以下是您应该做的布局:
也就是说,你应该在一段时间内,而不是两段时间内。在
相关问题 更多 >
编程相关推荐