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]
2 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]2 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
Considering current online newspaper editions and the characteristics of digital age media, how do you think newspaper design mi
NeX [460]
One way that a newspaper design may change in the future is that they will only be available in an interactive online edition. The correct answer is B. <span />
6 0
3 years ago
Michael is discussing various project needs with his team. Match Michael’s statement with the way project management can help th
Reika [66]

Answer:

get out there outside and get out and see what you do when you're ready for a workout or a day off and you're going through the

7 0
3 years ago
Which type of business is best for Juanita to start? a corporation, because she needs a large investment to get started a sole p
Vedmedyk [2.9K]

A sole proprietorship, because she will work alone from home a franchise

7 0
3 years ago
Read 2 more answers
What are the best apps to learn coding
Soloha48 [4]
Khan Academy is a good website and also has an app
6 0
3 years ago
Read 2 more answers
What is the output of the code below?
sp2606 [1]

Answer:

The output of the given code is 56.43

Explanation:

As the code is given in java language the following are the code

public class code

{

public static void main(String[] args)

{

double num = 56.4321;

System.out.print("%.2f", 56.4321);

}

}

The %f means that it print the floating point number and .2 means that it print the first two digit of the given number after the point .

so " %.2f "means that it print the value first 2 digit of floating point number after the point .

Therefore it print 56.43

7 0
3 years ago
Other questions:
  • Company A is setting up a network of mostly Windows machines. Which networking file system protocol would you recommend for maxi
    5·1 answer
  • If you ping a device, you are using the______protocol
    11·1 answer
  • One megabyte is approximately __________.
    7·2 answers
  • 12. Which one of the following items would you be most likely to keep in a database?
    10·1 answer
  • The practice of texting is most popular and what age group
    12·2 answers
  • When gathering information about certain occupations, be sure to understand how you are paid. What is the difference between a s
    12·2 answers
  • A half-life is the amount of time it takes for a substance or entity to fall to half its original value. Caffeine has a half-lif
    12·1 answer
  • Besides earning money why do people work​
    6·2 answers
  • Point out the wrong statement: SOA eliminates the use of application boundaries, the traditional methods where security is at th
    11·1 answer
  • Describe the user interface in other high-technology devices commonly found in the home or office, such as a smartphone, HD tele
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!