我正在为我的入门级python编程课做一个家庭作业任务,而且我遇到了一个问题。指令如下:如何计算使用while循环的python代码中的条目数?
修改find_sum()函数,以便输出输入值的平均值。与以前的average()函数不同,我们不能使用len()函数来查找序列的长度;相反,你将不得不引入另一个变量来“输入”它们输入的值。
我不确定如何计算输入的数量,如果任何人都可以给我一个好的起点,那太棒了!
# Finds the total of a sequence of numbers entered by user
def find_sum():
total = 0
entry = raw_input("Enter a value, or q to quit: ")
while entry != "q":
total += int(entry)
entry = raw_input("Enter a value, or q to quit: ")
print "The total is", total
纠正你的python缩进! – Rubens 2013-03-06 03:30:49
(好的第一个问题,顺便说一句 - 欢迎来到堆栈溢出) – BlackVegetable 2013-03-06 03:34:42