Write a Python program to calculate the sum and average of n integer numbers. Input 0 to finish


Introduction

Write a Python program to calculate the sum and average of n integer numbers. Input 0 to finish.

I have used python 3.7 compiler for debugging purpose.


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

  1. print("Input some integers to calculate their sum and average. Input 0 to exit.")
  2.  
  3. count = 0
  4. sum = 0.0
  5. number = 1
  6.  
  7. while number != 0:
  8. number = int(input(""))
  9. sum = sum + number
  10. count += 1
  11.  
  12. if count == 0:
  13. print("Input some numbers")
  14. else:
  15. print("Average and Sum of the above numbers are: ", sum / count)

Result

python language techstudy.org

     





Related Topics




Popular Posts