0
n = input("Please enter an arithmetic expression: ")
i = 0
for i in range(len(n)):
    if i <len(n): 
    

as you can see after the if statement I have hit a wall and I'm confused about how to go about this. if the user were to input (100+50+1-1) the output would be 150 so to speak. so the plan is how would I go about calculating the input of the arithmetic expression the user puts in.

vDeadrise
  • 1
  • 1
  • 1
    Please provide a text-based code and expected output. – Dariyoush Dec 12 '21 at 16:56
  • Does this answer your question? [Evaluating a mathematical expression in a string](https://stackoverflow.com/questions/2371436/evaluating-a-mathematical-expression-in-a-string) – Gereon Dec 12 '21 at 17:49

1 Answers1

0

how about:

# input by the user, e.g.: 150+12+12
n = input("Please enter an arithmetic expression: ") 
new = ''.join((i if i in '1234567890' else ' ') for i in n)
digit = [int(i) for i in new.split()]
print(digit)

output:

[150, 12, 12]

or with regular expression, you can do sth like (d means digits range from (0,9) and + meaning 1 or more times occurrence):

import re
d = re.findall(r'\d+', n)
d = [int(i) for i in d]
print(d)

output:

[150, 12, 12]
Dariyoush
  • 500
  • 4
  • 16