我試圖在python中重複地請求輸入,並且一旦輸入字符串'q'就會中斷循環並返回輸入的平均值。我不知道爲什麼這不起作用。循環輸入並找到輸入q時的列表的平均值
def listave(list):
UserInput = input('Enter integer (q to quit):')
list.append(UserInput)
while UserInput != 'q':
UserInput = input('Enter integer (q to quit:)')
if isinstance(UserInput, int) == True:
list.append(UserInput)
elif UserInput == 'q':
break
list.pop()
print('Average: ', float(sum(list)/len(list)))
listave(list)