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 is a data broker?
AleksAgata [21]

Answer:

The correct option is a.

A business that collects personal information about consumers and sells that information to other organizations.

Explanation:

Data brokers, also known as data suppliers, data fetchers, information brokers, or even data providers are businesses or companies (even individuals) that, on the most basic level, source and aggregate data and information (mostly information that are meant to be confidential or that are in the real sense difficult to get) and then resell them to third parties. These third parties could be other data brokers.  

They collect data and information from a wide range of resources and sources - offline and/or online e.g web access history, bank details, credit card information, official records (such as birth and marriage certificates, driver's licenses).  

Brokers can steal round about any information. Examples of information that brokers legally or illegally steal are full name, residential address, marital status, age, gender, national identification number, bank verification number. Brokers and hackers are siblings.

A couple types of data brokers are:

1. Those for fraud detection

2. Those for risk mitigation  

Hope this helps!

6 0
3 years ago
0 50 100 150 200 250 300 350 400 Shape Size These shapes are the correct 50 01 100 150 Pattern Reference If you don't have red,
cricket20 [7]

Answer:

0 540 100 200 350 400 550 600 750

Explanation:

hope this helped

4 0
3 years ago
Read 2 more answers
The following code does not work as intended. It is meant to input two test grades and return the average in decimal format:
vredina [299]

Answer:

Type casting error

Explanation:

Logically, the program is correct and it is expected to return the average value. However, test1 and test2 are int values and when you applies any algebraic expression on Int, it will result into Int.

So, in this part (test1 + test2 )/2, two integers are adding and the final result is still an integer and this part will act as an integer even if you multiple or divide with any external number.

For example,

test1 = 4

test2 = 5

test1 + test2 = 9

Now, if you divide it by 2, it will still react as an integer portion. So, 9/2 would result in 4 instead of 4.5. All the calculation is done on the right side before assigning it to a double variable. Therefore, the double variable is still getting the int value and your program is not working correctly.

The solution is to typecast the "(test1 + test2 )/2" portion to double using Double.valueOf(test1 + test2)/2 ;

I have also attached the working code below.

import java.util.Scanner;

public class Main

{

public static void main(String[] args) {

 System.out.println("Hello World");

 Scanner scan = new Scanner (System.in);

 int test1 = scan.nextInt();

       int test2 = scan.nextInt();

       double average = Double.valueOf(test1 + test2)/2 ;

       System.out.println("Answer: " + average);

}

}

4 0
3 years ago
katniss dismisses effie's metaphor because, literally, she knows pearls cannot be created with pressurised coal,they come from w
Marta_Voda [28]

Answer:

oysters

Explanation:

oysters form pearls inside their mouths, it's a very long process, and most oysters never finish or do them

please give brainliest

8 0
3 years ago
Read 2 more answers
1.How do we insert pictures in a word document ?<br>2.How to print a document in a word document? ​
Olenka [21]

Answer:

Explanation:

Place your insertion point where you want the image to appear.

Select the Insert tab.

Click the Picture command in the Illustrations group. The Insert Picture dialog box appears.

Select the desired image file, then click Insert to add it to your document. Selecting an image file.

6 0
3 years ago
Other questions:
  • Naseer has inserted an image into his document but needs the image to appear on its own line.
    14·2 answers
  • The main devices in a rectifier are:
    14·2 answers
  • Which collaboration website is best suited for social collaboration? www.media.iearn.org/projects www.meetup.com www.quest.nasa.
    9·1 answer
  • Your school has been declared a school of technology
    15·1 answer
  • D) Informal high level descuption of an algorithm in english kcalled
    9·2 answers
  • Misspelet errors are displays with a ...<br>.. below them<br>​
    10·1 answer
  • How is an interpreter different from a compiler?
    9·2 answers
  • A multiprocessor with 10 processors has 36 attached tape drives. A number of jobs have been submitted to the system where each j
    8·1 answer
  • Which internet explorer security feature restricts the browsing session information that can be tracked by external third-party
    12·1 answer
  • What is computer viras? Loist 2 preventive measures against it​
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!