Jun-16-2018, 06:53 PM
Hello,
My assignment is to take in an expression(such as 4 + 5), then calculate. I am to use the .split() function to separate parts of the statement. I think my program should work, I am having trouble converting my split expression into an int or float so the numbers can be used for calculation.
Thanks in advance for your help!
My assignment is to take in an expression(such as 4 + 5), then calculate. I am to use the .split() function to separate parts of the statement. I think my program should work, I am having trouble converting my split expression into an int or float so the numbers can be used for calculation.
Thanks in advance for your help!
''' Name: Julia Brushett ID#: 0532966 Date: June 16, 2018 Description: Assignment 6 ''' expression = str(input("Enter an expression for me to calculate: ")) expression = expression.split() op = expression[1] num1 = expression[0] num2 = expression[2] if (op == '+'): print("The sum is", num1 + num2) elif (op == '-'): print("The difference is", num1 - num2) elif (op == '*'): print("The product is", num1 * num2) elif (op == '/'): if (num2 == 0): print("The quotient is", num1 / num2) else: print("Cannot divide by 0") else: print("Invalid input")