python 程序小练习

时间:2023-02-14 12:11:17
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
    else:
        break
if count:
    print("count=",count, "total =", total,"mean=", total/count)
# 函数的创建和调用
def
get_int(msg): while True: try: i=int(input(msg)) return i except ValueError as err: print(err)
age = get_int("enter your age:")