+ 1
How to code a calculator
I keep trying but it isn't working. Please anyone help me https://sololearn.com/compiler-playground/cMJYvPV87vFL/?ref=app
4 Risposte
+ 2
@Ikechika Dickson
You had problems with your indention and some syntax errors and also some incomplete exception handling...
I have edited your code to the bare minimum and simple to understand, please note the indention.
Now its working perfectly. Below is the code.
#======== START OF CODE ========
first_number=int(input("Please enter first number: "))
print(first_number)
second_number=int(input("Please enter second number: "))
print(second_number)
operator = input("Choose an operation (+) or (-):")
if(operator[0]=="+"):
result = first_number + second_number
elif(operator[0]=="-"):
result = first_number - second_number
print(operator[0])
print("Your answer is" , result)
#======== END OF CODE ========
Let me know if you want me to add exception handling
0
The error message should be pretty clear - unexpected indent. Python uses indentation to distinguish structeres (e.g. where if starts and ends). Your indents are all messed up.
0
Can you code one and show me 🥲
0
mashtullah
Please explain better