fork download
  1. orig_input = input
  2. def input(msg):
  3. ipt = orig_input(msg)
  4. print(ipt)
  5. return ipt
  6.  
  7. #★ここから上は不要なので消してください★#
  8.  
  9. n = []
  10. t = 0
  11. while 0 <= t:
  12. t = input('整数の入力:')
  13. try:
  14. t = int(t)
  15. except ValueError:
  16. print('無効なデータ')
  17. t = 0
  18. continue
  19. n.append(t)
  20.  
  21. print(f'データ数:{len(n)}, 合計{sum(n)}, 平均{sum(n)/len(n):.1f}')
  22.  
Success #stdin #stdout 0.04s 9732KB
stdin
5
¥
0
-1
stdout
整数の入力:5
整数の入力:¥
無効なデータ
整数の入力:0
整数の入力:-1
データ数:3, 合計4, 平均1.3