Write a function called loops that accepts four arguments: (a) an integer named start, (b) an...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Write a function called loops that accepts four arguments: (a) an integer named start, (b) an integer named stop, (c) an integer named step, and (d) an iterable object (a list of ordered elements) named iterable. This function returns None. The function must inspect the step value and swap start and stop values so that it always produces a non-empty sequence of numbers, i.e. if the value of step is positive, the value of start must be less than the value of stop. If start is greater than stop - switch the values. It must first use a for loop to display the sequence of numbers horizontally and a while loop to display the sequence of numbers horizontally that includes the start and stop values. 1>>> [evaluate Lab1_JC.py] 2>>> iterable = [0, 1, 2, 3, 4] 3>>> loops (4, 2, 1, iterable) Output for 'for' loop: 234 Output for 'while' loop: 234 3) [20 marks] Write a function named main that takes no parameters and returns None. This function displays a menu (see sample output for menu), gets a choice from the user, and executes that choice. Choice 1 will demonstrate the functions for loops. The user should be asked for a choice until '5' is entered, which displays 'Goodbye' and terminates. Within this function, create the following iterable object: iterable = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] 1) [35 marks] Write a function called get_input that accepts an iterable object (a list of ordered elements) named iterable as its parameter and returns a 3-tuple. This function prompts the user for the following three values: (a) the letter 'A' or 'D', which will indicate ascending or descending (respectively), (b) an integer between 0 and the number of items in iterable, and (c) another integer between 0 and the number of items in iterable object. The function returns a 3-tuple: the first integer (as an integer), the second integer (as an integer), and either -1 (if the user entered 'D') or 1 (if the user entered 'A'). The function must perform error checking for all inputs and must accept both lower and uppercase characters for the first question. 1>>> [evaluate Lab1_JC.py] 2>>> iterable = [0, 1, 2, 3, 4] 3>>> val_1, val_2, step = get_input(iterable) Enter 'A' (for ascending) or 'D' (for descending): p Enter 'A' (for ascending) or 'D' (for descending): @ Enter 'A' (for ascending) or 'D' (for descending): 2.0 Enter 'A' (for ascending) or 'D' (for descending): Enter 'A' (for ascending) or 'D' (for descending): a Enter an index: -1 Invalid index. Enter one between 0 and 4: 7.3 Invalid index. Enter one between 0 and 4: 17 Invalid index. Enter one between 0 and 4: 4 Enter another index: 3 4>>>print(val_1, val_2, step) 4 31 Write a function called loops that accepts four arguments: (a) an integer named start, (b) an integer named stop, (c) an integer named step, and (d) an iterable object (a list of ordered elements) named iterable. This function returns None. The function must inspect the step value and swap start and stop values so that it always produces a non-empty sequence of numbers, i.e. if the value of step is positive, the value of start must be less than the value of stop. If start is greater than stop - switch the values. It must first use a for loop to display the sequence of numbers horizontally and a while loop to display the sequence of numbers horizontally that includes the start and stop values. 1>>> [evaluate Lab1_JC.py] 2>>> iterable = [0, 1, 2, 3, 4] 3>>> loops (4, 2, 1, iterable) Output for 'for' loop: 234 Output for 'while' loop: 234 3) [20 marks] Write a function named main that takes no parameters and returns None. This function displays a menu (see sample output for menu), gets a choice from the user, and executes that choice. Choice 1 will demonstrate the functions for loops. The user should be asked for a choice until '5' is entered, which displays 'Goodbye' and terminates. Within this function, create the following iterable object: iterable = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] 1) [35 marks] Write a function called get_input that accepts an iterable object (a list of ordered elements) named iterable as its parameter and returns a 3-tuple. This function prompts the user for the following three values: (a) the letter 'A' or 'D', which will indicate ascending or descending (respectively), (b) an integer between 0 and the number of items in iterable, and (c) another integer between 0 and the number of items in iterable object. The function returns a 3-tuple: the first integer (as an integer), the second integer (as an integer), and either -1 (if the user entered 'D') or 1 (if the user entered 'A'). The function must perform error checking for all inputs and must accept both lower and uppercase characters for the first question. 1>>> [evaluate Lab1_JC.py] 2>>> iterable = [0, 1, 2, 3, 4] 3>>> val_1, val_2, step = get_input(iterable) Enter 'A' (for ascending) or 'D' (for descending): p Enter 'A' (for ascending) or 'D' (for descending): @ Enter 'A' (for ascending) or 'D' (for descending): 2.0 Enter 'A' (for ascending) or 'D' (for descending): Enter 'A' (for ascending) or 'D' (for descending): a Enter an index: -1 Invalid index. Enter one between 0 and 4: 7.3 Invalid index. Enter one between 0 and 4: 17 Invalid index. Enter one between 0 and 4: 4 Enter another index: 3 4>>>print(val_1, val_2, step) 4 31
Expert Answer:
Related Book For
Entrepreneurial Finance
ISBN: 978-1305968356
6th edition
Authors: J. Chris Leach, Ronald W. Melicher
Posted Date:
Students also viewed these programming questions
-
You estimate that the dividend of stock AB will be $1.05/ share at YE 2024, then continue to grow in perpetuity at 3% per year. If AB's discount rate is 8%,what do you estimate the present value of...
-
(LO3, 4, 6) Exercises 4-24 Indirect cost rates and the death spiral Famous Flange Company manufactures a variety of special flanges for numerous customers. Annual capacity-related (manufacturing...
-
Let be a set and f, g: R. Assume max{f(x) + g(x) | x N}, max{f(x) | x}, and max{g(x) | x N} exist. (a) Show max{f(x) + g(x) | x N} max{f(x) | x N} + max{g(x) | x N}. (b) Show we can have strict...
-
Which of the following accounts does not have a normal credit balance? Service Revenue Sales Discounts Unearned Service Revenue Sales Revenue
-
What are the advantages and disadvantages of basing individual incentives on company-wide performance?
-
Balance these equations for reactions in basic solution. (a) Fe 2 S 3 + H 2 O + O 2 Fe(OH) 3 + S (b) O 2 - + H 2 O OH - + O 2 (c) CrI 3 + H 2 O 2 CrO 4 2- + IO 4 - (d) Ag + CN - + O 2 + OH - ...
-
P Ltd bought 40,000 shares in \($1\) Ltd and 27,000 shares in \($2\) Ltd on 31 December 2002. The following balance sheets were drafted as at 31 December 2003. You are to draw up a consolidated...
-
Orange County Chrome Company manufactures three chrome-plated productsautomobile bumpers, valve covers, and wheels. These products are manufactured in two production departments (Stamping and...
-
Make-or-Buy Decision Fremont Computer Company has been purchasing carrying cases for its portable computers at a purchase price of $55 per unit. The company, which is currently operating below full...
-
Kenny Young has started his own business, Home and Away Inspections. He inspects property for buyers and sellers of real estate. Young rents office space and has a part- time assistant to answer the...
-
Question 1 Let rt denotes the return of a financial asset and denotes the standard deviation of returns at time t. If rt follows an ARMA(2,2) model, rt = 0 + 01rt-1 + 2rt-2+ et +01t1 +02et-2, (a)...
-
Newhard Company applies overhead cost to jobs on the basis of 117% of direct labor cost. Job 313 includes 1,800 units and its job cost sheet contains $33,232 in direct materials and $10,400 in direct...
-
Bidding a job is inherently an expensive process, costing company resources in manpower and time. Discuss the risks of bidding construction jobs, including winning them.
-
What drives competition in commercial aircraft business? Is competition fair in commercial aircraft? As Boeing, what are your options for responding to Airbus? What would you do in 1991?
-
A company HOKKIE produces hockey sticks. The direct material per stick amounts to 15,00 EUR. The direct labour per stick equals 20,00 EUR. The total variable indirect production costs of the period...
-
Walmart's continuous replenishment system senses the level of stocks in Walmart stores and make orders to the suppliers to replenish the items that will be depleted soon. (4 points) What are the...
-
b. Based on Ms. Colby's sales growth forecast, how much does Charming Florist need in external funds for the upcoming fiscal year? (Do not round intermediate calculations and enter your answer in...
-
Highland Theatre is owned by Finnean Ferguson. At June 30, 2014, the ledger showed the following: Cash, $6,000; Land, $100,000; Buildings, $80,000; Equipment, $25,000; Accounts Payable, $5,000;...
-
You have been retained as a consultant for Ecosphere and tasked with assessing the financial viability of their commercial ventures. What types of financial ratios would you enlist in your report to...
-
Web-surfing exercise: Develop your own list of the five most important societal or economic trends currently shaping our society and providing major business opportunities. Use the Web to generate...
-
Following is the rate-of-return component information for First Venture investors: Rate Return Component Component Liquidity Premium .... 5% Risk-free Rate .. 6 Advisory Premium ....... 9 Market Risk...
-
10. ROLE REVERSAL Write a short-answer question focusing on one of the following: a fixture, an easement, or adverse possession.
-
11. ROLE REVERSAL Write a multiple-choice question highlighting the difference between any two of the following: a contract, an inter vivos gift, or a gift causa mortis.
-
Question: Shannon borrows Marty's car, but when she returns the auto, she hands the keys to Scott, who claims he is Marty's brother. Scott offers a driver's license and passport to reassure Shannon....
Study smarter with the SolutionInn App