Level A.
Write a program that calculates the sum of three numbers, entered in the form of a character string. All numbers are integers.

example = input('Введите пример: ') example = list(example) for i in range (len(example)): example[i] = int(example[i]) print (example) 
  • one
    @PythonLoveMe Try to change the sequence of writing the program. First write it in Python 3.7, and only then in Python 2.7. :) - Vlad from Moscow
  • Keep in mind for the future - Python 2 and Python 3 are not backward compatible. And in general, a program written in Python 2 will not work on Python 3 and vice versa - Dejsving
  • invalid literal for int () with base 10: '25 +30 'This is what a python error gives - PythonLoveMe
  • one
    There is no list() function in the code you gave. Guess exactly how you use some function, do not like here. Edit the question by adding all the necessary code. - Enikeyschik
  • 3
    @ Enikeyschik “do you think that you can write to the input" 25 + 30 "and get the result?" - this is exactly what worked in the second python - andreymal

1 answer 1

Why so complicate something? It's simple.

 example = input('Введите пример: ') #25+45+30 print(eval(example)) #100 

If to correct your example, here:

 example = input('Введите пример: ') example = example.split('+') s = 0 for i in range(len(example)): s += int(example[i]) print(s) 

But he will not take into account negative numbers. For this you need to do additional checks.