Create a function validate_input that repeatedly prompts the user for input until they enter an input...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Create a function validate_input that repeatedly prompts the user for input until they enter an input within a set of valid options. Arguments The function takes two arguments: • prompt: a string to print when asking user for input • valid inputs: a list of strings representing all options the user is restricted to Outputs/Returns The function should print prompt when asking the user for input. Upon an invalid input, please display the following message before prompting the user again: "Invalid input, please try again." Once a valid input is provided, the function should return it as a string. Example >>> validate_input("Please select an option (a, b, c): ", ["a", "b", "c"]) Please select an option (a, b, c): 1 Invalid input, please try again. Please select an option (a, b, c): 3 Invalid input, please try again. Please select an option (a, b, c): di Invalid input, please try again. Please select an option (a, b, c): a 1 def validate_input (prompt, valid_inputs): 12345 6 7 8 9 355W NIO 10 11 12 13 14 if 15 16 Repeatedly ask user for input until they enter an input within a set valid of options. :param prompt: The prompt to display to the user, string. :param valid_inputs: The range of values to accept, list :return: The user's input, string. || || || # Implement your solution below raise NotImplementedError == __name__ "__main__": # Enter test code below user_input = validate_input ("Please select an option (a, b, c) Create a function validate_input that repeatedly prompts the user for input until they enter an input within a set of valid options. Arguments The function takes two arguments: • prompt: a string to print when asking user for input • valid inputs: a list of strings representing all options the user is restricted to Outputs/Returns The function should print prompt when asking the user for input. Upon an invalid input, please display the following message before prompting the user again: "Invalid input, please try again." Once a valid input is provided, the function should return it as a string. Example >>> validate_input("Please select an option (a, b, c): ", ["a", "b", "c"]) Please select an option (a, b, c): 1 Invalid input, please try again. Please select an option (a, b, c): 3 Invalid input, please try again. Please select an option (a, b, c): di Invalid input, please try again. Please select an option (a, b, c): a 1 def validate_input (prompt, valid_inputs): 12345 6 7 8 9 355W NIO 10 11 12 13 14 if 15 16 Repeatedly ask user for input until they enter an input within a set valid of options. :param prompt: The prompt to display to the user, string. :param valid_inputs: The range of values to accept, list :return: The user's input, string. || || || # Implement your solution below raise NotImplementedError == __name__ "__main__": # Enter test code below user_input = validate_input ("Please select an option (a, b, c)
Expert Answer:
Answer rating: 100% (QA)
def validateinputprompt validinputs while True userinput inputprompt if userinput in ... View the full answer
Related Book For
Posted Date:
Students also viewed these programming questions
-
Widgetry Inc. sells two types of widgets: round widgets and square widgets. Round widgets retail for $1 each, while square widgets retail for $4 each. On Dec 1 st 2021, their customer purchases 2000...
-
What is the importance of financial management in a public and non-profit organization? What are the most common techniques used to manage different types of risks? Do you have any work experience in...
-
Assignment 5: Hash Table implementation andconcordance There are three parts to this assignment. In the first two parts,you will complete the implementation of a hash map and aconcordance program. In...
-
KEA10. LO 16.3 Use the following excerpts from Fruitcake Company's financial records to determine net cash flows from investing activities. Acquired new plant assets Collected interest on investment...
-
Find an equation of the tangent line to the curve at the given point. 7. y =1 + 2x - r (1. 2) 8. y = 2x + I, (4. 3) 9. y (x - 1/(x - 2). (3. 2) 10. y 2x/(x + 1). (0.0) %3D
-
Solve =) (8) (9) 5x+6ydydx =
-
Consider a correctly specified regression model with $p$ terms, including the intercept. Make the usual assumptions about $\varepsilon$. Prove that \[\sum_{i=1}^{n}...
-
Place the following activities in order from first to last to illustrate the capital budgeting process: a. Budget capital investments b. Project investments cash flows c. Perform post- audits d. Make...
-
Discuss the economic benefits for primary and secondary markets. Briefly explain your understanding of an IPO, the net valuation of a firm and what can happen once the shares are traded on secondary...
-
Presented below are annual coupon rates, yield rates, and expected duration for a series of debentures. Calculate the issuance price for each debenture assuming that the face value of each bond is...
-
Given today's real estate and interest rate market environments, what is the problem with defining a "Terminal CAP" with a normal distribution? Suggest a different kind of distribution that might be...
-
The graphs show that the three components of love, namely, passion, intimacy, and commitment, progress differently over time. Passion peaks early in a relationship and then declines. By contrast,...
-
The low-temperature condenser of a distillation column is to be operated using a propane refrigeration unit. The evaporator is to operate at -20C. The cooling duty is to be 10,000,000 kJ/ hr. The...
-
A regenerative Rankine cycle uses one open feedwater preheater and one closed feedwater preheater. Using the stream numbering from Fig. 5.6, and the specified conditions below, the plant capacity is...
-
A steam power plant operates on the Rankine cycle with reheat, using the specified conditions below. Using stream numbering from Fig. 5.3, for each of the options below, determine (a) The work output...
-
A steam power plant operates on the Rankine cycle according to the specified conditions below. Using stream numbering from Fig. 5.2, for each of the options below, determine: (a) The work output of...
-
Lithium crystallizes in a body centered cubic unit cell. What is the mass of one unit cell? Report answer in grams.
-
Explain the circumstances that could result in a long-term bank loan being shown in a statement of financial position as a current liability.
-
a. Create a class named Blanket with fields for a blankets size, color, material, and price. Include a constructor that sets default values for the fields as Twin, white, cotton, and $30.00. Include...
-
Name at least three classes to which each of these objects might belong: a. myGrandmothersBrooch b. eggsBenedict c. cookieMonster
-
Write an application for Lamberts Vacation Rentals. Use separate ButtonGroups to allow a client to select one of three locations, the number of bedrooms, and whether meals are included in the rental....
-
The treatment of outflows on account of dividend and interest is highly debatable as to their activity classification. Give a serious thought to the issue and express your opinion about the best...
-
Consider the same setting as Problem 18, but suppose instead 80% of the shareholders redeem their shares, and no warrants are exercised. Data from problem 18 a. What is the amount of cash per share...
-
Reliance Industries Ltd. is the biggest private sector company in India. The following fact sheet about the company and its peer group, as extracted from Capitaline Plus database is reproduced in the...
Study smarter with the SolutionInn App