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
"Which hash algorithm's primary design feature is two different and independent parallel chains of computation, the results of w
Galina-37 [17]

Answer:

Option C i.e., RIPEMD is the correct option for the following question.

Explanation:

Because RIPEMD is the algorithm that is used for the hash primary design characteristic which has two independent and unlike parallel chains of the calculation and computation and the outputs of which are then linked to the process at the end. It is also used for the safe process of replacing the 128-bit hash method.

Other options are wrong because these are not related to the following statement.

5 0
3 years ago
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
Employees information system source code ..please ​
Alexxx [7]

Answer:

def greetuser(username)

6 0
3 years ago
Describe 3 options that are available for the marquee and lasso tools
Dovator [93]
I’m just doing this because why not. Lol don’t read this.
4 0
3 years ago
Which of the following statements correctly instantiate the Rectangle object myRectangle? (i) myRectangle Rectangle = new Rectan
madreJ [45]

Answer:

The answer is "option iii"  .

Explanation:

In the given question it is defined that a class "Rectangle" is defined in the class a parameter constructor is created that accepts two parameters. In this question, we create an instance of the class. In object creation first, we define class name then object name and use new keyword in the Instance of class and pass parameters.

  • In option i), An object name is used first and then class name. It is not correct.
  • In option ii), In instance creation of the class, we do not use class keyword that's why it is wrong.

5 0
3 years ago
Read 2 more answers
Other questions:
  • HELP NOW PLZZ/ Question: Complete the sentence with the correct response.
    11·1 answer
  • To display measurements on the ruler while changing column widths, hold down the ________ key while dragging the marker.
    13·1 answer
  • 6.
    14·2 answers
  • Which word is most appropriate to describe a laptop?
    5·1 answer
  • What is the Matlab command to create a column vector with 11 equally spaced elements, whose first element is 2 and whose last is
    8·1 answer
  • Create a TicTacToe class that initializes a 3x3 board of "-" values. We will use this class in future exercises to fully build o
    9·1 answer
  • My mom hid my laptop and now I can't find it​
    9·1 answer
  • Write a C program that reads two hexadecimal values from the keyboard and then stores the two values into two variables of type
    15·1 answer
  • Which Internet connection type tends to use shared bandwidth?<br> Cable<br> Dial-up<br> DSL<br> ISDN
    5·2 answers
  • 13,Which hardware device is used in decoding the machine language version of an instruction in the Instruction Decode stage of t
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!