hi guys, i really need ur help in python with my homework, please :<

+1 vote
asked Apr 5 by DariaSNT (130 points)
Write a program that calculates the sum of three numbers entered as a character string. All numbers are integers.
Example:
Enter the expression:
12+3+45
Answer: 60

5 Answers

–1 vote
answered Apr 6 by Vaishnavi (190 points)
# Store input numbers
num1 = input('Enter first number: ')
num2 = input('Enter second number: ')
num3 = input('Enter third number :')
# Add three numbers
sum = float(num1) + float(num2) +float(num3)

# Display the sum
print('The sum of {0},{1} {2} is {3}'.format(num1, num2, num3, sum))
+1 vote
answered Apr 6 by Omkar Joshi (180 points)
a=input()
b=input()
c=input()

print("Sum of a ,b and c is",int(a)+int(b)+int(c))
0 votes
answered Apr 8 by Jag Man Gurung (220 points)
Hello there. You can use eval() function for your question.

expression = "12+3+45"
print(eval(expression))

Output: 60.
commented Apr 9 by DariaSNT (130 points)
thanks a lot!
0 votes
answered Apr 17 by Khadeja Y (160 points)

num = input("Enter the expression : \n")

print("Answer:",eval(num))

output: 

Enter the expression : 
12+3+45
Answer: 60

0 votes
answered Apr 24 by Anto (140 points)
I know the "eval" function is made for this, but I'm guessing you're supposed to find the solution yourself, not already made.

What about (Python3.x) :

line = input().split('+')
try:
    numbers = [int(n) for n in line]
except ValueError:
    print("Invalid line format.")
    exit(1)
else:
    result = sum(numbers)
    print(result)
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...