← Back to challenges

Clear Brackets

PythonHardstringslogicvalidation

Instructions

Create a function brackets() that takes a string and checks that the brackets in the math expression are correct. The function should return True or False.

Examples

brackets("(a*(b-c)..... )") ➞ True

brackets(")(a-b-45/7*(a-34))") ➞ False

brackets("sin(90...)+.............cos1)") ➞ False

Notes

  • The string may not contain brackets, then return True.
  • String may contain spaces.
  • The string may be empty.
python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.