1 while True: 2 a = 0 3 n = input('从0开始加到您所输入的数字:') 4 if n.isdigit() == True: 5 n = int(n) 6 for i in range(n+1): 7 a += i 8 else: 9 print('计算完成,结果为', a) 10 s = input('输入q退出或者任意字符继续 : ') 11 if s == 'q': 12 break 13 else: 14 print('请输入正整数!') 15 print('程序结束!')