2016-04-27 77 views

回答

1

你想了解接下來的事情是數據結構如此list。然後您可以使用list.append即時將項目添加到列表中。

不過,值得注意的是,你從哪裏學習Python,肯定會在某個或那個點上超越列表。

3

您可以將這些值附加到列表中。總和,然後除以平均長度。

nums = [] 
while True: 
    x = input("Enter a number:") 
    if x == 'end': 
     avg = sum(nums)/len(nums) 
     print("And the average is....", avg) 
     break 
    elif x.isdigit(): 
     nums.append(int(x)) 
    else: 
     print("Try again.") 
+0

感謝我的一個好友建議我追加值以及不太確定如何做到現在! –

0

如果您的意思是您要存儲所有給定的x值,請使用列表。 l = [] l.append(x)。

相關問題