在求和之后,不能进行求平均。不知道循环坏在哪了。
menu = int(raw_input('1: sum, 2: average,X: quit')) while menu != 'X': a = [] i = 0 if menu == 1: for i in range(0, 5): a += [raw_input('type a number')] b = 0 for n in a: b += float(n) print b elif menu == 2: for i in range(0, 5): a += [raw_input('type a number')] b = 0 for n in a: b += float(n) print b / 5.0 else: "please type correct number" menu = (raw_input('1: sum, 2: average,X: quit'))
这样写~