about | help | code help+videos | done | prefs |
Given an algebraic expression, y, and a variable name, x, define D(y, x) to return the derivative of the expression y with respect to x. The the second argument, x, must be a variable name, which we will represent as a string, like 'x' or 'z'. The first argument, y, must be an algebraic expression. An algebraic expression can be a variable name (represented as a string), a number (represented as a Python number), or a complex expression (represented as a list of the form [exp, op, exp], where op is one of the five basic operators: '+', '-', '*', '/', and '^' (exponentiation), and exp can be any expression under these rules). (You need only consider exponents to integer powers.) As an example, the expression "x + (x - y)" would be represented as the list ['x', '+', ['x', '-', 'y']]. The derivative of this with respect to x is 2, but we will accept the expression [1, '+', [1, '-', 0]], because that is what you get by a straightforward application of the basic rules of differentiation. (In the next exercise we will get the answer 2.) (NOTE: this isn't an ideal problem for the CodingBat format, because sometimes there are multiple answers which are both equally simple, but different. If your program disagrees with the answers we have in the test cases, but your answer is mathematically correct, don't worry about it.) ...Save, Compile, Run (ctrl-enter) |
Progress graphs:
Your progress graph for this problem
Random user progress graph for this problem
Random Epic Progress Graph
Difficulty: 530 Post-solution available
Copyright Nick Parlante 2017 - privacy