Execute the code using the following test data then answer the questions: Test data: 10, 101,-1,5,...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Execute the code using the following test data then answer the questions: Test data: 10, 101,-1,5, 0 a) Describe what happened when you entered each value. b) What does the counter variable do? What does the accumulator variable do? Why do they have to be initialized to zero before we use them? c) What type of variable is good data and how is it being used in the program? Test data: 0 d) Describe what happened when the sentinel value was the first number input. e) How could we alter the code to prevent this from happening? #Constants MIN = 1 MAX = 100 SENTINEL = 0 def main(): count = 0 #counter variable total = 0 #accumulator variable int_value = get_integer() #priming read while int_value != SENTINEL: count += 1 total + int_value int value = get_integer() #loop read print(Total number of values entered is', count) print("The sum of the values entered is', total) print("The average value is', total/count) def get_integer0: num_input = int(input('Enter a value between 1 and 100, 0 to stop: ')) good_data = MIN <= num_input <= MAX or num_input == SENTINEL while not good_data: print('Value out of range') num_input = int(input('Enter a value between 1 and 100, 0 to stop:':')) good_data = MIN <= num_input <= MAX or num_input == SENTINEL return num_input main() Execute the code using the following test data then answer the questions: Test data: 10, 101,-1,5, 0 a) Describe what happened when you entered each value. b) What does the counter variable do? What does the accumulator variable do? Why do they have to be initialized to zero before we use them? c) What type of variable is good data and how is it being used in the program? Test data: 0 d) Describe what happened when the sentinel value was the first number input. e) How could we alter the code to prevent this from happening? #Constants MIN = 1 MAX = 100 SENTINEL = 0 def main(): count = 0 #counter variable total = 0 #accumulator variable int_value = get_integer() #priming read while int_value != SENTINEL: count += 1 total + int_value int value = get_integer() #loop read print(Total number of values entered is', count) print("The sum of the values entered is', total) print("The average value is', total/count) def get_integer0: num_input = int(input('Enter a value between 1 and 100, 0 to stop: ')) good_data = MIN <= num_input <= MAX or num_input == SENTINEL while not good_data: print('Value out of range') num_input = int(input('Enter a value between 1 and 100, 0 to stop:':')) good_data = MIN <= num_input <= MAX or num_input == SENTINEL return num_input main()
Expert Answer:
Answer rating: 100% (QA)
Lets go through the code and test data step by step Test data 10 101 1 5 0 a Describe what happened when you entered each value 1 10 The code accepts ... View the full answer
Related Book For
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill
Posted Date:
Students also viewed these programming questions
-
How do biotechnologists employ recombinant DNA technology to engineer novel genetic constructs with precision, and what implications does this hold for the advancement of personalized medicine?
-
We will be working with a company called Global Bike Inc., (GBI). Information regarding GBI follows. Company History Global Bike Inc. has a pragmatic design philosophy that comes from its deep roots...
-
Managing Scope Changes Case Study Scope changes on a project can occur regardless of how well the project is planned or executed. Scope changes can be the result of something that was omitted during...
-
Although epoxides are always considered to have their oxygen atom as part of a threemembered ring, the prefix epoxy in the IUPAC system of nomenclature can be used to denote a cyclic ether of various...
-
(a) The linear and angular velocities of each sphere immediately after the impact, (b) The velocity of each sphere after it has started rolling uniformly. B
-
Assume the same facts as in Problem 41, except that Gordon and Fawn are husband and wife (not brother and sister). a. What are the gift tax consequences when the real estate was purchased? b. What...
-
The owner of an ice cream store asks 75 people which flavor of ice cream they prefer. Thirteen of them say strawberry, 11 say chocolate, 24 say vanilla, and 27 provide a flavor other than strawberry,...
-
Two charges are placed as shown in Fig. 17-35 with q1 = 1.5μC and Q2 = 3.3μC. Find the potential difference between points A and B. 91 0.10 m 13 0.10 m
-
The value of assets amounts to 1,700,000 , the expected instantaneous rate of return and corresponding volatility are 8 and 13 percent. Time to maturity of the outstanding debt is 1 year. Investors...
-
A periodic signal x[n] of fundamental period N can be represented by its Fourier series If you consider this a representation of x[n] (a) Is x 1 [n] = x[n N 0 ] for any value of N 0 periodic? If so...
-
10. Two radioactive nuclides A and B with half-lives TA and TB= 2TA. Assuming the initial numbers of both nuclides are equal, which of the following statements is correct? A) Nuclide A decays faster...
-
1. In a perfect world, how does muni bonds would pay interest? 2. What did the new study find? How did the researchers arrive at their conclusion? 3. Explain the correlation between the greater...
-
You are considering buying a 30 year bond issued by Microsoft for $95.00. The bond has a par value of $100 and pays a coupon of 7.5% annually. If you reinvest all your coupon payment at the yield to...
-
What happens if a person sells a right to receive his/her salary, and how is it taxed?
-
Question What happens to the basis of an appreciated asset when a person dies, and why is it a significant consideration in estate planning?
-
Barry buys 100 shares of MSFT stock on April 1, 2008, for $50,000. On June 1, 2009, he sells all 100 shares for $70,000. Barry earns $150,000 per year. At what rate, if any, is this gain taxed?...
-
In the following project, you will perform What-If Analysis tocalculate budget information for your universitys Valentines Dayformal. Steps to Perform: Step Instructions Points Possible 1 Download...
-
What mass of KBr (in grams) should you use to make 350.0 mL of a 1.30 M KBr solution?
-
William sold Section 1245 property for $25,000 in 2012. The property cost $35,000 when it was purchased 5 years ago. The depreciation claimed on the property was $16,000. a. Calculate the adjusted...
-
John Williams (age 42) is a single taxpayer, and he lives at 1324 Forest Dr., Reno, NV 89501. His Social Security number is 555-94-9358. John's earnings and withholdings as the manager of a local...
-
a. Wilson filed his individual tax return on the original due date, but failed to pay $700 in taxes that were due with the return. If Wilson pays the taxes exactly 2 months late, calculate the amount...
-
Apple stock is selling for \($120\) per share. Call options with a \($117\) exercise price are priced at \($12.\) What is the intrinsic value of the option, and what is the time value?
-
Refer to Problem 14.9. What would the loss of the seller of the put option be if, at expiration, XLB is trading at \($20?\) What would the profit of the seller be if, at expiration, XLB is trading at...
-
Ibrahim bought 200 shares of a stock trading in the Abu Dhabi Securities Exchange at AED 12 (United Arab Emirates dirham) per share. Over time, the price of the stock increased to AED 18 per share....
Study smarter with the SolutionInn App