So I'm very new to Python and have done very little coding since ActionScript 3, but I'd like to start learning Python as it seems way more functional than anything I've used in the past.
The best way to do that for me is to make something, and then have someone (like you fine folks) to look at it and make the code more efficient, or critique the way it is written.
`
import re
def loop():
problem = input("what is your math problem?\n")
problem_string = re.split('(\d+)', problem)
first_number = float(problem_string[1])
second_number = float(problem_string[3])
problem_string[2] = problem_string[2].replace(" ", "")
math_unit = problem_string[2]
if math_unit == '*':
print(first_number * second_number)
loop()
elif math_unit == '+':
print(first_number + second_number)
loop()
elif math_unit == '-':
print(first_number - second_number)
loop()
elif math_unit == '/':
print(first_number / second_number)
loop()
loop()
`
Here is my simple calculator. I played with having 3 numbers and 2 mathunits instead of one but it started to get a bit complicated for it's purpose. Is there a more efficient way of doing the math within python.
I thought I could perhaps use the string itself to do the math, but that might be crazy talk. I also barely understand the use of re.split('(\d+)', problem)
but I know it is separating the string in to something way more helpful, giving me the ability to have 1129501352 + 125156 instead of just 2 + 2.