我的程序需要接受來自用戶的輸入,但輸入類似Ted,24
,所以每個輸入都將用逗號分隔,我知道將它們放入列表中將是一個好主意,但我也需要獲得平均年齡。這裏是我到目前爲止的代碼:如何將一個值放在另一個列表中?
namesAge = []
count = 0
ave = 0
total = 0
while True:
mess=input("Enter name and age: ")
if mess == "":
print(namesAge)
print ("We have ",count," names")
print ("Total age is",total)
break
if "," in mess:
namesAge.append(mess)
count = count + 1
else:
print("invalid input")
不工作.. Hmmmmm – 2014-10-07 13:28:49