| 135 | |
| 136 | |
| 137 | def handle_pi(string, pi): |
| 138 | |
| 139 | if isinstance(string, str) and "\pi" in string: |
| 140 | # Find the first occurrence of "\pi" |
| 141 | idx = string.find("\pi") |
| 142 | |
| 143 | # Iterate over the string and find all occurrences of "\pi" with a valid previous character |
| 144 | while idx != -1: |
| 145 | |
| 146 | if idx > 0 and string[idx-1].isdigit(): |
| 147 | # Replace "\pi" with "*math.pi" if the previous character is a digit |
| 148 | string = string[:idx] + f"*{pi}" + string[idx+3:] |
| 149 | else: |
| 150 | # Replace "\pi" with "1*math.pi" if the previous character is not a digit |
| 151 | string = string[:idx] + f"1*{pi}" + string[idx+3:] |
| 152 | |
| 153 | # Find the next occurrence of "\pi" |
| 154 | idx = string.find("\pi", idx + 1) |
| 155 | |
| 156 | # Evaluate the expression using eval() function |
| 157 | try: |
| 158 | string = eval(string) |
| 159 | except: |
| 160 | pass |
| 161 | |
| 162 | return string |
| 163 | |
| 164 | def math_equal( |
| 165 | prediction: Union[bool, float, str], |