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
Your colleague received an E-mail from a bank that is requesting credit card and PIN number information. Which of the following
uysha [10]

Answer: A) Phishing

Explanation:

Phishing is type of attack in computer field that is processed to hack or steal the data of authorized user.The attacker acts as trusted party and then interacts with the authorized user through email or messages to gain  confidential information like pin code, credit card number, login details etc of that user.

  • According to the question, colleague is experiencing phishing as he has been requested for pin-code and credit-card number from a wrong source behaving as authorized bank.
  • Other options are incorrect because ransomware is attack that asks for ransom from authorized user for reviving their access. on system. Spoofing is falsifying as some other party to receive advantage.
  • Mail poisoning is inclusion of inappropriate details in email such as invalid email address etc.
  • Thus, the correct option is option(A).
0 0
3 years ago
True or False? Any edition or version of Windows can join a domain.
Veseljchak [2.6K]

Answer: TRUE! 100%

If I was helpful i would to be rated brainliest please thank you!

Explanation:

8 0
2 years ago
Identify aspects of contemporary society that might lend themselves to a Commedia-type scenario or short play (ex: the British R
Helen [10]

Answer:

pls type clearly to understand i can't understand

4 0
3 years ago
Please pass this on... ( #helpsavelives )
olya-2409 [2.1K]

Answer:

Thank you

Explanation:

That made my day. I will make sure to pass it on.

4 0
3 years ago
if you exit a program without saving the document on which you are working, or the computer accidentally losses electrical power
MrRissso [65]
Depends on which program you are using. Some programs automatically save your work, even if you exit out of it or turn off your computer
6 0
3 years ago
Other questions:
  • What computer has best software
    5·1 answer
  • Hope wants to add a third use at the end of her
    14·1 answer
  • Prominent is another word for stands out. True False
    13·1 answer
  • Write a function named printtriangle that receives a parameter that holds a non-negative integer value and prints a triangle of
    7·1 answer
  • If you want to adjust the width of a column manually, move your mouse over the _______ column boundary and click and drag until
    9·1 answer
  • A communications objective is:
    12·1 answer
  • Which process could you use to add a table to a document?
    14·1 answer
  • Moore's Law postulates that:This task contains the radio buttons and checkboxes for options. The shortcut keys to perform this t
    6·1 answer
  • What are possible penalties if a designer is caught breaking copyright laws?
    13·1 answer
  • For this assignment your are to implement the Pet Class described in Programming Exercise 1, starting on page 494 in our textboo
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!