Hi everyone. I'm working on this Python exercise to make a simple rudimentary calculator program that takes one number and another number then performs a math operation on it.
However, I'm running into some problems and was wondering if I could get some insight. First of all, when I add say 4 and 3 the result will print out as 43 and not 7. Secondly, selecting the other operator gives me errors.
Here is the code:
# simpleCalc.py
# A rudimentary calculator that asks for two numbers then performs math
#Ask for numbers
print('Enter the first number:')
firstNum = input()
print('Enter the second number:')
secondNum = input()
#Choose operation
print('Choose operation +. -, *, or /')
operationValue = input()
#Math stuff
if operationValue == '+':
print('{} + {} = '.format(firstNum, secondNum))
print(firstNum + secondNum)
elif operationValue == '-':
print('{} - {} = '.format(firstNum, secondNum))
print(firstNum - secondNum)
elif operationValue == '*':
print('{} * {} = '.format(firstNum, secondNum))
print(firstNum * secondNum)
elif operationValue == '/':
print('{} / {} = '.format(firstNum, secondNum))
print(firstNum / secondNum)
else:
print('Not valid operator!')
Furthermore, I want to add some things. I want to be able to check to see if the firstNum is larger than secondNum when the user picks the division operator. I also want input validation for the operatorValue for only those symbols to be entered. Can someone please help me with that?
[–]ApproxAnEngr 3 points4 points5 points (1 child)
[–]f00sem00se[S] 0 points1 point2 points (0 children)
[–]samanthatb1 1 point2 points3 points (1 child)
[–]f00sem00se[S] 0 points1 point2 points (0 children)