python輸入若干個(gè)0–100的成績?
平均分的編碼是:
numbers=[]
while True:
x=input('請輸入一個(gè)整數(shù):')
try:
numbers.append(int(x))
except:
print('不是整數(shù)')
while True:
flag=input('繼續(xù)輸入嗎?(yes/no)')
if flag.lower()not in('yes','no'):
print('只能輸入yes或no')
else:
breakif flag.lower()=='no':
break
print(sum(numbers)/len(numbers))