Answer to Question #217317 in Python for adhichinna

Question #217317

Build an algorithm to parse and process the dynamic expression based on the dictionary

provided. The expression basically consists of Operators, Variables, and Parentheses.

Parentheses have higher precedence (i.e the subexpression in the parentheses should be

executed first)

Basically, the algorithm should support two operators - AND (concatenates the two variables) &

OR (provides first variable value if it is available. Otherwise, go for the second variable)

The algorithm should parse the given expression and apply the respective dictionary values on

the expression and provides the respective computed results.

INPUTS OUTPUT

Sno Expression Dictionary Expected Results

1 A and B

2 A and C

3 D or B

4 A or B

5 A and B and C {'A':'Hello', 'B': 'World', 'C': 'Buddy'}

6 A and (B or C) {'A':'Hello', 'B': 'World', 'C': 'Buddy'}

7 A and (C or D) {'A':'Hello', 'B': 'World', 'C': 'Buddy'}

8 A and (B or C) and D {'A':'Hello', 'C': 'Buddy', ‘D’: ‘Welcome’}


1
Expert's answer
2021-07-14T18:33:22-0400
def search(arr, x):
    for index, value in enumerate(arr):
        if value == x:
            return index
    return -1
  
arr = [1, 2,3,4]
x = 30
print(x, "is present at index",
      search(arr, x))

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS