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
What are storage devices? write two such devices​
Ira Lisetskai [31]

Answer:

two types of storage devices used with computers a primary storage device such as r a m and the secondary storage device such as a hard drive secondary storage can be removable internet or external

Explanation:

hope it is helpful for you please make me brilliant only if you like this answers

8 0
2 years ago
Read 2 more answers
What are the different types of Network Connectivity Devices?
mylen [45]

Explanation:

Types of network devices

Hub.

Switch.

Router.

Bridge.

Gateway.

Modem.

Repeater.

Access Point.

HOPE THIS HELPS YOU THANK YOU.

3 0
2 years ago
Color of seagrass beds on navigational charts? Please quickly
Nadya [2.5K]
Hello! The color of seagrass beds on navigational charts are brown, because they are in shallow areas and it helps you know the locations of them.
5 0
3 years ago
Memory and processor both have big impact on the performance of a pc. <br>•true <br>•false <br>​
meriva

Answer:

true

Explanation:

they really do

the memory saves

while the processor determine the speed of the computer .... The processor also determine the price is the pc as it is the brain of the computer

4 0
3 years ago
Which site had a major influence on the social gaming site Friendster? A. Spoke B. Ryze C. XING D. LinkedIn
Natali5045456 [20]

I believe the correct answer is B; ryze

I am not 100% but am like 80% sure

5 0
2 years ago
Other questions:
  • A document repository is down when you attempt to access it. which isa principle is being violated?
    13·1 answer
  • Robin maintains a web page for updating the metro timings in the city. He would like the website to display the present day's sc
    6·1 answer
  • In Paint, which of the following are ways to use a picture that you have saved on your computer? (Select all that apply.)
    8·1 answer
  • Help me out for this one
    12·1 answer
  • What is the best way to improve the following code fragment? if ((counter % 10) == 0) { System.out.println("Counter is divisible
    11·1 answer
  • write a java program that prompts the user to enter scores (each number an integer from 0 to 10) and prints the following output
    13·1 answer
  • Which person would be the best fit for a career in the Information Technology field?
    6·2 answers
  • How do you increase the number of tries by one?
    10·1 answer
  • 8. SQL, Oracle Report, and Visual Basic are all examples under the
    7·1 answer
  • If a person communicates indirectly and attaches little value to
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!