python3程序开发指南(第2版)
print("Type integers,each followed by Enter;or just Enter to finish")
total=0
count=0
while True:
line=input("integer:")
if line:
try:
number=int(line)
except ValueError as err:
print(err)
continue
total+=number
count+=1
except EOFError:
break
if count:
print("count=",count,"total=",total,"mean=",total/count)
执行:
File "E:\pythonspace\p`\src\p2.py", line 19
except EOFError:
^
SyntaxError: invali
本帖最后由 whitelotus19 于 2014-11-10 15:27 编辑
#!/usr/bin/env python
# -*- coding: utf-8 -*-
print("Type integers,each followed by Enter;or just Enter to finish")
total=0
count=0
while True:
line=input("integer:")
if line:
try:
number=int(line)
except ValueError as err:
print(err)
continue
else:
break
total+=number
count+=1
if count:
print("count=",count,"total=",total,"mean=",total/count)
页:
[1]