Advertisement
Mary_99

average

Mar 28th, 2020
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.74 KB | None | 0 0
  1. import os
  2. import sys
  3.  
  4. '''
  5. write a programm that finds the avarage of all positive
  6. numbers accepted from keyboard.The terminating value is zero,
  7. not included to numbers. Negative numbers are skipped,
  8. not included to the calcualtion.
  9. '''
  10. def averrage():
  11.     inputFromUser = None
  12.     sum = 0
  13.     count = 0
  14.     ave = 0
  15.      
  16.     while True:
  17.         try:
  18.             while(inputFromUser != 0):
  19.                 inputFromUser = int(input("EnterNumbers: "))
  20.                 if(inputFromUser > 0):
  21.                     sum += inputFromUser
  22.                     count += 1
  23.                     ave = sum / count
  24.         except ValueError:
  25.             print("please enter numbers")
  26.             continue
  27.         print(ave)
  28.         break
  29. averrage()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement