+ 1
Please help me to make mini calculator
first = input("Enter first number :") operator = input("Enter operation (+,-,*,/,%) : ") second = input("Enter second number :") first = int(first) second = int(second) if operator == "+": print(first + second) elif operator == "-": print(first - second) elif operator == "*": print(first * second) elif operator == "/": print(first / second) elif operator == "%": print(first % second) else: print("invalid operation") Please tell me what is wrong with this code series
6 odpowiedzi
+ 1
Save code in playground ans share link here..
If this is all same code you are trying then you have identation errors.. and those can be tested only playground..
Remove spaces before opearator and second..
+ 1
The second and third line should be at the same indentation level to the first line. Always remember where to indent lines, in conditionals, loops, functions etc.
https://code.sololearn.com/cT5BRIbkia21/?ref=app
+ 1
guys will you tell me what is identation
+ 1
The code link added by @ipang has clear examples about proper identation.
It's about adding spaces to form same block of code. . A free line should start at from the left most side..
If you familiar with other languages like c/c++/java, those uses curly braces { } instead. But python uses Identation.
Read the code in above link... Hope that clears...
+ 1
To make things simpler you could use the eval() function which is built into python
Es
operation = input("Enter an operation: ")
print(eval(operation))
These 2 lines of code will take even more operations and give the complessive result, by making the calculations in the correct order
Es.
Input: 5+4*2
Output : 13
0
identation erro, you should avoid unnessary space before statement