Write a program that calculates the average of N integers. The program should prompt the
user to enter the value for N and then afterward must enter all N numbers. If the user enters a
negative value for N, then an exception should be thrown (and caught) with the message “ N
must be positive.” If there is any exception as the user is entering the N numbers, an error
message should be displayed, and the user prompted to enter the number again.

Answers

Answer 1

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.


Related Questions

what feature should be used before a document is printed

Answers

Print preview is a feature that displays on the screen what a hard copy would look like when printed. By using print preview, you can find any errors that may exist or fix the layout before printing, which can save ink or toner and paper by not having to print more than once.

Drag the tiles to the correct boxes to complete the palrs.
Match the types of letters with their descriptions.
letter of interest
cover letter
thank you letter
letter of recommendation
discusses how you meet job requirements
>
reiterates why you're the best candidate for the job
>
tells more about your character and who you are
expresses your interest in working for a company

Answers

Answer:

Letter of interest> tells you more about your character and who you are expresses your interest in working for a company

Letter of recommendation> reiterates why you're the best candidate for the job

Cover letter> discusses how you meet job requirements

Hope this helped!

Answer:

Discusses how you meet job requirements = Cover Letter

Expresses your interest in working for a company = Letter of Interest

Tells more about your character and who you are = Letter of Recommendation

Reiterates why you're the best candidate for the job = Thank You Letter

What are url addresses for visiting websites? And what are the different parts of a URL? Answer it in a 1-2 paragraph

Answers

A URL is a website link which consists of //https and the title of the website you are going to. A URL helps guide and memorize certain links and websites. Also some URL links are fake and give false advertisement or false information especially when looking into things that happen everyday like the news. You can tell this by seeing if the url link is a trustworthy link. I hope this helps maybe you can expand on it if it’s not long enough

Answer:

Please read explanation

Explanation:

URL is the short form for "Uniform Resource Locator". A uniform resource locator tells the location of a website to the browser.

Parts of URL:

There are three main parts of URL

ProtocolDomain nameExtension

Protocol defines the type of protocol used for communicating with the website while the domain name is the name assigned to the IP address and the mapping is stored in domain name server and extension tells the type of website i.e.

.com means commercial

.org means non-profitable organization

.edu means educational website

An additional element is path which change with the website navigation.

Files can be stored on hard drives, network drives, or external drives, but not in the cloud.
True
False

Folders provide a method for organizing files.
True
False

Answers

The first one is false and the second is true

Answer: (1) False, (2) True

Explanation:

If a function is called more than once in a program, the values stored in the function's local variables do not _________ between function calls. g

Answers

Answer:

persist

Explanation:

Calling a function Within a program, can be regarded to as specifying of the name of the function when it is within a statement or it could be by the function itself, it possible for a particular function to call another function, in a case wherby a function returns a value, assignment or using the value to variable is not necessary. It should be noted that If a function is called more than once in a program, the values stored in the function's local variables do not persist between function calls

turns on her laptop and gets the error message "OS NOT FOUND." She checks the hard disk for damage or loose cable, but that is not the case. What could be a possible cause?

Answers

It needs an Operating System like a cable or something that will help it operate look for more and double check

Which statement is true?
1)A deque is a type of collection,
2)A collection is a type of deque.
3)A list is a type of deque.
4)A deque is a type of list.

Answers

Answer:

1. A deque is a type of collection.

Explanation:

The statement that is true is as follows:

A deque is a type of collection.

Thus, the correct option for this question is A.

What is Deque?

Deque may be defined as an ordered and systematic collection of items similar to the queue. It is also known as a double-ended queue. It consists of two ends, a front, and a rear, and the items remain positioned in the collection.

According to the context of this question, a deque is a kind of collection that holds data and information identical to a queue. From here, elements can be added to or eliminated from either the front or back very efficiently.

It is also often called a head-tail linked list. Though properly this signifies specific data with appropriate structure that has been the implementation of a deque.

Therefore, a deque is a type of collection that is a true statement. Thus, the correct option for this question is A.

To learn more about Deque, refer to the link:

https://brainly.com/question/16750037

#SPJ2

Hi, Everybody i have a question it is almost my B-day i want this lego set
(Nintendo Entertainment System™) BUT THEY ARE SOLD OUT
I NEED HALP

Answers

Answer:

You can look at different websites of look on an app for people selling it, or something :p

Explanation:

Write a loop to print all elements in hourly_temperature. Separate elements with a -> surrounded by spaces. Sample output for the given program: (must be in python)
90 -> 92 -> 94 -> 95
Note: There is a space after 95.
------------------------------------------------------------------------------------------------------------------------
hourly_temperature = [90, 92, 94, 95]
for temp in hourly_temperature:
for index,temp in enumerate(str(temp)):
if index != len(temp)-1:
print(temp,'->',end=' ')
else:
print(temp, end='')
print('') # print newline
------------------------------------------------------------------------------------------------------------------------
My expected out is:
90 -> 92 -> 94 -> 95
I keep getting:
90 -> 92 -> 94 -> 95 ->
NOTE: I can't edit the last line "print('') #print newline"

Answers

Answer:

Following are the code to this question:

hourly_temperature = [90, 92, 94, 95]#defining a list that holds values

c= 0#defining a variable c

for temp in hourly_temperature:#defining a for loop to count list values

   c+= 1#defining c variable to increment the value of c

   for index,temp1 in enumerate(str(temp)):#defining for loop for spacing the list value

       if index == len(str(temp))-1 and c!= len(hourly_temperature):#defining if block that checks the length of list

           print(temp1,'->',end=' ')#print value

       elif c == len(hourly_temperature) and index == len(str(temp)) - 1:#defining elif block that checks the length of list

           print(temp1, end=' ')#print value

       else:#defining else block

           print(temp1, end='')#print value

Output:

90 -> 92 -> 94 -> 95  

Explanation:

In the above-given code, a list "hourly_temperature" is declared, in which an integer variable c is declared, that holds an integer value that is equal to 0, and two for loop is declared, and in the first loop is used for count list value, and inside the for loop is uses enumerate method to assigns an index for each item and use the conditional statement to check each list value and provide space in each element value.

As an interviewer, it is not necessary to be at eye level with interviewee

True
False

Answers

Answer:

True

Explanation:

Have a great day

Answer:

True

Hope this helps

While your hands are on home row, both of your thumbs are on _____.

Answers

Answer:

While your hands are on home row, both of your thumbs are on Space-barI know this will definitely help✍️✍️✍️
Other Questions
Find a formula for the general term or of the sequence assuming the pattern of the first few termscontinues.{14, 19, 24, 29, 34, ...}Assume the first term is a1.an=? Which type of energydoes respiration release?chemicalthermalpotentialkinetic Jackie weighed an Amazon box that was delivered to her home.The box weighed 192 ounces.How much does the box weight in pounds Sharon is driving on a straight road. She is driving north, and her speed isdecreasing. If north is the positive direction, which of the followingstatements is accurate?A) Her velocity is positive, and her acceleration is negative.B) Her velocity is negative, and her acceleration is negative.C) Her velocity is negative, and her acceleration is positive.D) Her velocity is positive, and her acceleration is positive.Plzz help Fill in the missing numbers to complete the pattern:1.31, 1.81, _____ ,2.81, _____ ,3.81 One advantage of putting information into a database is that you can filter the data.O TrueO False Helpp me please find the angle (where the question mark is ) 10 pointsss Nicky and his parents recently Immigrated to the United States from Syria. Nicky attends school and is having a hardtime learning about his new country. His parents are interested in what happens in their community as well. Whichfeature of national Identity is likely to make it hard for them to feel a part of the United States? Language innovation competition form of government What is true of congenital musculoskeletaldiseases?are present at birthdevelop after age 50develop in late childhoodare caused by growing up in a pollutedenvironment What is the correct definition of word count? the number of words in the bio the number of words in the byline the number of words in the title the number of words in a piece of writing What is a detailed definition of Treaty of Versailles? TY IF U HELPDoes obedience to church Authority make one more or less free? explain the strongly blown ballon gets blasted why? I need help can you help me 8. Solve the equation.25 - 3x = 40a.x=5b.x=1C. X=-1d. x= 10Help ! What angered Mather Byles? Jackson is at colletibles fair. He has exactly $8 and will purchase a collectibles card from a vendor for $5. What percentage will jackson spend on the purchase?A. 0.625%B. 3%C. 40%D. 62.5%Please help me out or explain how do i do it, but if you give me the answer ill give you brainliest! PLEASE HELP IT WOULD MEAN A LOT :( Line BC is represented by 3x + 2y = 8. Line AD is represented by 3x 2y = 6. What is the relationship of line BC to line AD? Explain how the sum of the equations demonstrates this relationship. ASAP please help me I need this quick The question and answers are in the picture