Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this question, please help the tutors to implement a function to check whether a set of parameters adheres to the rules of advanced argument

image text in transcribedimage text in transcribedimage text in transcribed

In this question, please help the tutors to implement a function to check whether a set of parameters adheres to the rules of advanced argument passing. Input: An arbitrary number of string type arguments. Each string value represents one of the parameters that the tutors would like to use in their function (e.g. "param_name", "param_name=10", "*param_name"). The given parameters will be one of the following: normal argument, default argument, *args, and **kwargs. Given the input, your function has two tasks: 1. Verify and output if the set of parameters are valid so that it can be used in a function header by checking the following: The order of the parameters is valid There are neither multiple *args nor multiple **kwargs 2. Correct the parameters if they are invalid by: Correct the order based on the rules we learn in class Remove all *args except for the first *args in the original list and remove all **kwargs except for the first **kwargs . Output: A tuple with two items: a list of strings that are the corrected parameters, and a boolean that tells if the original parameters were correct or not. Examples If I want to check the following function header is valid or not: def example(slope, *constants, intercept) The function call will be the following where each argument is a string of example's parameters: parameter_debugger('slope', '*constants', 'intercept') The output will be the following tuple whose first item is the list of parameters in the correct order, and the second item is False which tells the original parameters were incorrect: (['slope', 'intercept', '*constants'], False) Given the output, now I can create the function with the correct header: def example(slope, intercept, *constants) Notes: You should make sure that your outputted list does not change the order of the same parameter types, e.g. if given "disti" & "dist2", you should never return a list with "dist2" coming before "dist1"). Hint The valid order of parameters is based on the four types of parameters (normal, default, *args, **kwargs). Review the lecture slides and try defining your own function with the different orders of the four parameter types. def parameter_debugger (*params) : >>> parameter_debugger('first', 'second=30', '*third', '**fourth') (['first', 'second=30', '*third', '**fourth'], True) >>> parameter_debugger('slope', '*constants', 'intercept') (['slope', 'intercept', '*constants'], False) >>> parameter_debugger('*tutor', 'professor="Marina"', '*ta', 'me') (['me', 'professor="Marina"', '*tutor'], False) # YOUR CODE IS HERE #

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Conceptual Database Design An Entity Relationship Approach

Authors: Carol Batini, Stefano Ceri, Shamkant B. Navathe

1st Edition

0805302441, 978-0805302448

More Books

Students also viewed these Databases questions

Question

Discuss the history of human resource management (HRM).

Answered: 1 week ago