Here you have to do some mathematical operations on a "dirty string". This kata checks some basics, it's not too difficult.


__So what to do?__

Input: String which consists of two positive numbers (doubles) and exactly one operator like `+, -, * or /` always between these numbers. The string is dirty, which means that there are different characters inside too, not only numbers and the operator. You have to combine all digits left and right, perhaps with "." inside (doubles), and to calculate the result which has to be rounded to an integer and converted to a string at the end.

### Easy example:

```
Input: "gdfgdf234dg54gf*23oP42"
Output: "54929268" (because 23454*2342=54929268)
```

First there are some static tests, later on random tests too...

### Hope you have fun! :-)

Source: codewars | Difficulty: EASY
Tags: String algorithms

Fundamentals

Data structures

Mathematics

Starter code: def calculate_string(st):
	

Solutions:
import re

def calculate_string(st):
	st = re.sub('[^-+*/\\d.]', '', st)
	result = eval(st)
	return str(int(round(result)))


def calculate_string(st: str) -> str:
	return f"{eval(''.join((s for s in st if s in '0123456789.+-/*'))):.0f}"


def calculate_string(st):
	clean = ''
	for i in st:
		if i.isdigit() or i == '.':
			clean += i
		elif i in ['+', '-', '*', '/']:
			clean += i
			operator = i
	clean = clean.split(operator)
	print(clean)
	if operator == '+':
		return str(round(float(clean[0]) + float(clean[1])))
	elif operator == '-':
		return str(round(float(clean[0]) - float(clean[1])))
	elif operator == '*':
		return str(round(float(clean[0]) * float(clean[1])))
	else:
		return str(round(float(clean[0]) / float(clean[1])))


import re

def calculate_string(st):
	return str(round(eval(re.sub('[^0-9\\-\\+\\*\\/\\.]', '', st))))


import re

def calculate_string(st):
	return str(round(eval(re.sub('([^\\d\\.\\/\\*\\-\\+])+', '', st))))


def calculate_string(stg):
	return f"{eval(''.join((c for c in stg if c.isdecimal() or c in '.+-*/'))):.0f}"


def calculate_string(st):
	return str(round(eval(''.join((a for a in st if a in '0123456789.+-*/')))))


import re
from operator import itruediv, imul, isub, iadd

def calculate_string(st):
	op = itruediv if '/' in st else iadd if '+' in st else isub if '-' in st else imul
	l = [eval(''.join(re.findall('[\\d.]', s))) for s in re.split('[-+*/]', st)]
	return str(round(op(l[0], l[1])))


def calculate_string(st):
	clean = '+-*/1234567890.'
	st = ''.join([char for char in st if char in clean])
	return str(round(eval(st)))