6 kyu

Plus or Minus

Description:

In this task you are required to determine an expression consisting of variables and operators.

  • The variables are all single lower-case alphabetic characters
  • Each variable occurs only once in the expression
  • The operators are either + or -
  • There are no parentheses.

For example: "x-y+z" or "-d-b-c+w"

You must implement a function plus_or_minus which will be passed two parameters:

  • variables : a string consisting of just the variables in the order that they appear in the expression. For example: "xyz" or "dbcw" (The length of the input string will be between 1 and 26 inclusive.)
  • test : a test function which takes as its parameter a list of numeric values to be substituted for the variables in variables. The function will return the result of evaluation the expression.

You must return the expression with the variables in the same order as the input and with the correct operators inserted. Omit any leading + from the start of the expression.

Example 1:

expression = "x-y+z"
variables = "xyz"
test([1, 2, 3]) = 2

Example 2:

expression = "-d-b-c+w"
variables = "dbcw"
test([3, 0, -1, 0.5]) = -1.5

Here's the catch: In each test case you may only call test once. Subsequent calls will return None

Mathematics

Stats:

CreatedMar 18, 2024
PublishedMar 18, 2024
Warriors Trained822
Total Skips30
Total Code Submissions444
Total Times Completed81
Python Completions81
Total Stars15
% of votes with a positive feedback rating95% of 28
Total "Very Satisfied" Votes26
Total "Somewhat Satisfied" Votes1
Total "Not Satisfied" Votes1
Total Rank Assessments5
Average Assessed Rank
6 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • Paul Robertson Avatar
  • dfhwze Avatar
  • avermakov Avatar
Ad