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
-
Under what conditions is it appropriate for a business to use the composite method of depreciation for its plant assets? What are the advantages and disadvantages of this method?
-
(a) When n balls, numbered 1, 2, 3, ... , n are taken in succession from a container, a rencontre occurs if the mth ball withdrawn is numbered m, for some 1 m n. Find the probability of getting (i)...
-
Jalila owns and manages a small business (E Connections) that sells electronic connectors and network components. The following industries purchase products from E Connections: mechanical and plant...
-
The following information is stored in two relational database files: Employee Master File Social Security number Name Address Date hired Hourly wage rate Marital status Number of exempt ions Weekly...
-
5. Identify the type of each of the following reactions stating reason for your answers: (a) Fe2O3 + 2Al 6. Al2O3 + 2Fe + heat (b) Pb(NO3)2 + 2KI PbI2 + 2KNO heat (c) ZnCOg ZnO + CO2 In the...
-
Consider a 4-year 10% coupon bond with nominal capital 100. You can 'strip off the coupon payments - the first due in exactly one year, the second in two years, the third in three years and the final...
-
The following balance results taken from FIFA 2020 financial statement reports ,you are requested to complete the data below: Net cash (used)/generated by operating activities? Net cash...
-
Demonstrate for yourself that it is impossible to avoid communicating nonverbally by trying not to communicate with a friend or family member. (You be the judge of whether to tell the other person...
-
Identify an important relational dimension (positive or troublesome) in a current or past close relationship. Describe to your classmates how you did express, or could have expressed, your thoughts...
-
Watch a TV show or movie and identify examples of the following nonverbal functions: Creating and maintaining relationships Regulating interaction Influencing others or self Concealing or deceiving...
-
With a group of classmates, practice rephrasing each of the following you statements in I and/or we language: Youre not telling me the truth! You only think of yourself! Dont be so touchy! You dont...
-
You can get a better appreciation of the importance of punctuation by using the format pictured in Figure 5.3 to diagram the following situations: a. A father and daughter are growing more and more...
-
MAT 102 Graphing Quadratic Functions Worksheet Show your work to receive credit. f(x)=x-4 (continued) Graph the function showing vertex, x-intercept(s), y-intercept, and additional 2 points....
-
Archangel Corporation prepared the following variance report. Instructions Fill in the appropriate amounts or letters for the question marks in the report. ARCHANGEL CORPORATION Variance...
-
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...
-
A change in chromosome structure that does not involve a change in the total amount of genetic material is a. a deletion. b. a duplication. c. an inversion. d. none of the above.
-
The term endopolyploidy refers to the phenomenon of having a. too many chromosomes. b. extra chromosomes inside the cell nucleus. c. extra sets of chromosomes in certain cells of the body. d. extra...
-
Which of the following is a type of plasmid? a. F factor (fertility factor) b. R factor (resistance plasmid) c. Virulence plasmids d. All of the above are types of plasmids.
Study smarter with the SolutionInn App