Question
ANSWER IN PYTHON Consider a simple arithmetic expression of the form operand operator operand (exactly two operands, and one operator) where the operands are either
ANSWER IN PYTHON
Consider a simple arithmetic expression of the form "operand operator operand" (exactly two operands, and one operator) where the operands are either variables or integer constants, and the operator is one of +, -, /, or *.
Variable names can only have letters (upper or lowercase), digits and underscores, but the first character cannot be a digit. There's no limit to the length of a variable name. Integer constants may have leading zeros. There may or may not be whitespaces around the operator, or around the entire expression.
Examples of legitimate expressions:
' 01*278 '
'_abc_1x2 +12'
Example of non-legit expressions:
'25/1ABC' (1ABCD is not a variable name, starts with digit)
'a & b' ('&' is not one of the 4 allowed operators)
'? a * 12 + 5 (extraneous stuff at beginning/end)
Write a regular expression to match and extract the operands and operator (in the order in which they appear) from this form of arithmetic expression. Assume that there will be a call re.findall that will apply your regular expression to a string.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started