Note: This kata is inspired by [Convert a Number to a String!](http://www.codewars.com/kata/convert-a-number-to-a-string/). Try that one too.

## Description

We need a function that can transform a string into a number. What ways of achieving this do you know?

Note: Don't worry, all inputs will be strings, and every string is a perfectly valid representation of an integral number.

## Examples

```python
stringToNumber("1234") == 1234
stringToNumber("605" ) == 605
stringToNumber("1405") == 1405
stringToNumber("-7"  ) == -7
```

Source: codewars | Difficulty: EASY
Tags: String algorithms

Fundamentals

Starter code: def string_to_number(s):
	

Solutions:
def string_to_number(s):
	return int(s)


string_to_number = int


string_to_number = lambda n: int(n)


string_to_number = lambda s: int(s)


def string_to_number(s):
	i = int(s)
	return i


def string_to_number(s):
	number = int(s)
	return number


def string_to_number(s):
	result = 0
	place = 1
	i = len(s) - 1
	while i >= 0:
		digit = s[i]
		if digit == '1':
			result += place
		elif digit == '2':
			result += 2 * place
		elif digit == '3':
			result += 3 * place
		elif digit == '4':
			result += 4 * place
		elif digit == '5':
			result += 5 * place
		elif digit == '6':
			result += 6 * place
		elif digit == '7':
			result += 7 * place
		elif digit == '8':
			result += 8 * place
		elif digit == '9':
			result += 9 * place
		elif digit == '-':
			result = -result
		place *= 10
		i -= 1
	return result


string_to_number = eval


def string_to_number(s):
	return float(str(float(str(int(s)))))


from re import match as m
string_to_number = lambda s: eval(s) if m('^[-+]?\\d+$', s) else None


def string_to_number(s):
	num = 0
	flag = False
	if s[0] == '-':
		flag = True
	for i in range(len(s)):
		if flag and i == 0:
			continue
		else:
			num += int(s[i])
			if i != len(s) - 1:
				num *= 10
	return num if not flag else -1 * num


def string_to_number(s):
	negative = False
	if s[0] == '-':
		s = s[1:]
		negative = True
	if s.isdigit():
		return -int(s) if negative == True else int(s)


def string_to_number(s):
	new_list = list(s)
	flag = True
	if new_list[0] == '-':
		new_list.pop(0)
		flag = False
	test_list = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
	for i in range(0, len(new_list)):
		if new_list[i] not in test_list:
			for j in range(i, len(new_list)):
				new_list.pop(i)
			break
	num_list = new_list[-1::-1]
	total = 0
	for i in range(0, len(num_list)):
		num = int(num_list[i])
		total += num * 10 ** i
	total = total if flag else -1 * total
	return total


import pandas as pd

def string_to_number(s):
	number = int(s)
	return number


def string_to_number(s):
	return eval(s)


def string_to_number(s):
	ch = 0
	for i in s:
		if i.isdigit():
			ch = ch * 10 + int(i)
	return ch if s[0] != '-' else -ch


def string_to_number(s):
	res = 0
	neg = 1
	print(s)
	l = len(s) - 1
	for i in s:
		if i == '-':
			neg = -1
			l = l - 1
		else:
			res += int(i) * 10 ** l
			l = l - 1
		print(res)
	return res * neg


def string_to_number(s):
	ans = 0
	counter = 1
	for i in s[::-1]:
		if i == '-':
			ans *= -1
		else:
			ans += int(i) * counter
			counter *= 10
	return ans


def string_to_number(s):
	try:
		return int(s)
	except:
		pass


def string_to_number(s):
	a = int(s)
	return a
string_to_number('1234')


def string_to_number(s):
	if s == str(s):
		return int(s)
	else:
		return 'Error'


def string_to_number(s):
	return int(s)
string_to_number('23')


def string_to_number(s: str) -> int:
	result: int = int(s)
	return result


def string_to_number(s):
	x = 0
	yygq = 1 if s[0] == '-' else 0
	for i in range(yygq, len(s)):
		x += (ord(s[i]) - 48) * 10 ** (len(s) - i - 1)
	return -x if yygq == 1 else x


def string_to_number(s):
	y = int(s)
	return y
string_to_number('50')


def string_to_number(s):
	newInt = int(s)
	return newInt


def string_to_number(num):
	return int(num)


def string_to_number(s):
	result = 0
	for i in range(len(s)):
		result = result * 10 + int(s[i]) if s[i] in '0123456789' else result
	return -result if s[0] == '-' else result


def string_to_number(s):
	return int(s)
print(string_to_number('605'))


def string_to_number(s):
	nummer = int(s)
	return nummer


import string
a = string

def string_to_number(a):
	int(a)
	return int(a)
if a == str(a):
	string_to_number(a)


def string_to_number(s):
	try:
		return int(s)
	except:
		print('not a number.')


def string_to_number(s):
	nums = int(s)
	return nums
print(string_to_number('1333'))


def string_to_number(s):
	return int(s, base=10)


def string_to_number(s):
	vlo = int(s)
	return vlo


def string_to_number(s):
	s = int(s)
	return s
s = '234'
print(string_to_number(s))


def string_to_number(s):
	if '-' not in s:
		return int(s)
	else:
		return float(s)


def string_to_number(s):
	int_number = int(s)
	return int_number


def string_to_number(s):
	if s[0] == '-':
		return -1 * int(s[1:])
	return int(s)


def string_to_number(n):
	return int(n)


def string_to_number(s):
	newStr = int(s, 10)
	return newStr


def string_to_number(s):
	return int(s)
print(string_to_number('34'))


def string_to_number(s):
	x = eval(s)
	return x


def string_to_number(string):
	string = int(string)
	return string


def string_to_number(s):
	string = str(s)
	jo = ''.join(string)
	num = int(jo)
	return num


def string_to_number(s):
	if s[0] != '-':
		d = 1
	else:
		d = -1
		s = s[1:]
	num = 0
	for c in range(len(s) - 1, -1, -1):
		num += int(s[c]) * d
		d *= 10
	return num


def string_to_number(s):
	if s == str(s):
		return int(s)
	return str(s)


def string_to_number(s):
	return int(s)
string_to_number('6')


def string_to_number(s):
	num_string = int(s)
	return num_string


string_to_number = lambda a: int(a)


def string_to_number(a):
	return float(a)


def string_to_number(s):
	if s != int:
		num = int(s)
	return num


def string_to_number(s):
	soluzione = int(s)
	return soluzione


def string_to_number(s):
	a = s
	n = int(a)
	return n


def string_to_number(s):
	wynik = int(s)
	return wynik


def string_to_number(s):
	value = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}
	result = 0
	pos_or_neg = 1
	for i in s:
		if i == '-':
			pos_or_neg = -1
		if i in value:
			result = result * 10 + value[i]
	return result * pos_or_neg


def string_to_number(s):
	if s.isdigit():
		return int(s)
	else:
		return -int(s[1:])


def string_to_number(s):
	if s[0] == '-':
		mul = -1
		i = 1
	else:
		mul = 1
		i = 0
	ans = 0
	while i < len(s):
		x = s[i]
		x = ord(x) - ord('0')
		ans = ans * 10 + x
		i = i + 1
	return ans * mul


def string_to_number(s):
	numb = int(s)
	return numb


def string_to_number(s):
	try:
		return int(s)
	except:
		Gary


def string_to_number(s):
	convert_number = int(s)
	return convert_number


def string_to_number(s):
	num = float(s)
	return num


def string_to_number(s):
	if s is None:
		return None
	return int(s)


def string_to_number(s):
	return int(s)
	if s[0] == '-':
		for (i, value) in enumerate(s[1:]):
			number += int(value) ** 10 ^ len(s) - i - 1
		number = -1 * number
	else:
		for (i, value) in enumerate(s):
			print(i, value)
			number = number + int(value) * 10 ** (len(s) - i - 1)
			print(number, 10 ^ len(s) - i - 1)
	return number


def string_to_number(s):
	try:
		int(s)
		return int(s)
	except e:
		print('not an integer')
		pass


def string_to_number(s):
	try:
		return int(s)
	except ValueError:
		print('Input data cannot be represented as a number')
		return None


def string_to_number(s):
	binary = bin(int(s))
	print(s + ' in binary: ' + binary)
	hexa = hex(int(binary, 2))
	print(binary + ' in hex: ' + hexa)
	remove0x = hexa.replace('0x', '')
	reversed = '0x' + remove0x[::-1]
	print('Reversed: ' + reversed)
	multiplied = ''
	for i in range(len(remove0x)):
		multiplied += chr(ord(remove0x[i]) * (10 * (len(remove0x) - i)))
	print('Multiplied: ' + multiplied)
	see = 0
	for i in multiplied:
		see += ord(i)
	print('Ascii added: ' + str(see))
	rereversed = '0x' + reversed.replace('0x', '')[::-1]
	print(rereversed + ' is ' + reversed + ' reversed again.')
	if '-' in rereversed:
		rereversed = '-' + rereversed.replace('-', '')
	print('If we change that to integer and return it...  Hmm!')
	return int(rereversed, 16)


def string_to_number(s):
	number = 0
	if s[0] == '-':
		for n in s[1:]:
			number = number * 10 + (ord(n) - ord('0'))
		return -number
	else:
		for n in s:
			number = number * 10 + (ord(n) - ord('0'))
		return number


def string_to_number(s):
	for number in s:
		if number in '+-1234567890':
			return int(s)


def string_to_number(s):
	transformar = int(s)
	return transformar
string_to_number('1234')


def string_to_number(s):
	str_int = int(s)
	return str_int


def string_to_number(s):
	new_number = int(s)
	return new_number


def string_to_number(s):
	neg = s[0] == '-'
	num = 0
	i = 0
	if neg:
		i = 1
	while i < len(s):
		num = num * 10 + (ord(s[i]) - ord('0'))
		i += 1
	return (-1 if neg else 1) * num


def string_to_number(s):
	v = int(s)
	return v


def string_to_number(s):
	return int(''.join(list(s)))


def string_to_number(s):
	x = int(s)
	return x
print('1234')


def string_to_number(s):
	return int(s)
string_to_number('555')


def string_to_number(n):
	num = int(n)
	return num