1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
PSYCHO15rus [73]
3 years ago
12

Write a program that calculates the average of N integers. The program should prompt the

Computers and Technology
1 answer:
r-ruslan [8.4K]3 years ago
5 0

Answer:

def Average(num):

   if num == 0:

       return 0

   val = 0

   trueNum = num

   for i in range(0, num):

       try:

           val += int(input("Enter value (%d out of %d): " % (i+1,num)))

       except Exception as e:

           print ("Error processing value. Non integer detected.")

           try:

               val += int(input("Enter value (%d out of %d): " % (i+1,num)))

           except Exception as e:

               print ("Error processing value. Non integer detected.")

               print ("OMITTING value from average.")

               trueNum -= 1

   return val/trueNum

def main():

   try:

       num = int(input("Enter a value N for amount of items: "))

       if num < 0:

           raise(ValueError)

   except ValueError:

       print ("N must be positive integer.")

       exit(1)

   print("Average: ", Average(num))

   exit(0)

if __name__ == "__main__":

   main()

Explanation:

This program is written in Python to collect some integer value from the user as an upper bound of integers to be input for an average.  Using this upper bound, the program checks to validate it is indeed an integer.  If it not an integer, then the program alerts the user and terminates.  If it is a user, the Average function is called to begin calculation.  Inside the Average function, the user is prompted for an integer value repeatedly up until the upper bound.  Using the sum of these values, the program calculates the average.  If the user inputs a non integer value, the program will alert the user that the value must be an integer and ask again.  If the user again inputs a non integer value, that iteration will be omitted from the final average.  The program this prints the calculated average to the user.

Cheers.

You might be interested in
A photograph with more yellows has which mood
just olya [345]

Answer:

Yellow reflects most of the light and thus draws lots of attention; too bright a shade will leave you irritated. Prolonged exposure can also have a tiring effect. It is best used in down-tones; as background for white articles/figures. Green is the color of tranquility and vibrant.

Explanation:

6 0
3 years ago
Read 2 more answers
A cyberbully is someone who invades another person’s privacy by
e-lub [12.9K]
Insulting or harassing them over the Internet
8 0
4 years ago
Read 2 more answers
16 POINTS
Nostrana [21]
It think it's a Nested List.
Im so sorry if this is wrong
6 0
3 years ago
Write a program to print sum on first 10 natural numbers.
Kamila [148]

sum of 10 natural number is 55

4 0
3 years ago
While their rational of a drug user's mind knows that they shouldn't use it again, another part of the brain overrides such warn
Levart [38]
I'm unsure in What it is you're asking.

While their rational of a drug user's mind???
this alone makes no direct sense.

also I'm unsure what Computers and Technology have to do with drug user's or their brains.

I can leave you with this a drug addict is and addict hence the name it's an addiction so there is no rationality or distinctiveness in knowing not to use again until one truly wants to get help and change for the better of self.

hope this helps
4 0
3 years ago
Other questions:
  • A(n application system is the master controller for all the activities that take place within a computer system. _______________
    15·1 answer
  • The disk drive is a secondary storage device that stores data by _____ encoding it onto a spinning circular disk.
    14·1 answer
  • B. What is a window?​
    8·2 answers
  • Write a program that determines the value of the coins in a jar and prints the total in dollars and cents. Read integer values t
    5·1 answer
  • The following equations estimate the calories burned when exercising (source): Men: Calories = ( (Age x 0.2017) — (Weight x 0.09
    11·1 answer
  • Although your project has been accepted by the customer, the contract with the system vendor specifies that it will support the
    13·1 answer
  • Briefly explain what an array is. As part of your answer make use of a labelled example to show the declaration and components o
    5·1 answer
  • Can someone help me calculate this Multimedia math:
    11·1 answer
  • IF YOU LOVE GOD HELP ME......What should be covered in the conclusion of a presentation?
    11·2 answers
  • Artificial intelligence (ai) in perspective is a complex and interdisciplinary field that involves several specialties, includin
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!