+ 1
My calculator is not working- bit help plz
19 Answers
+ 3
The reasons because your code isn't working is:
1. You must indent the the piece code of "if" || "elif" statements.
2. The Python interpreter of Sololearn is so bad, use Pydroid 3 on Play Store for check your errors.
3. You can do this for do the sum, substraction, multiply, and module:
num1 = int(input("Please enter the number 1: "))
num2 = int(input("Please enter the number 2: "))
____
Then you have these two numbers, you can define functions for the operations like this:
# for sum
def sum(num1, num2):
print("\n", (num1 + num2))
# for substraction
def subs(num1, num2):
print("\n", (num1 - num2))
## do equal >>
#def mult
# def module
________
Then, do you have the function created, only you must call it.
You can call the function of this manner:
# if user statement
if user == "sum":
sum(num1,num2)
# num1 and num2 are parameters, in # this case are integer variables
#defined by user input.
______
Can you understand that?. Chat me if you have more doubts.
+ 1
Nvm guys
I got it
The parts we're not inside the block
+ 1
Hmm yes, functions will take some time to understand
+ 1
Have fun!
+ 1
Use curly braces to put all the content of if on it limit so that your system know what is the end of if so that elif start from there ok and idk why you use sys. exit because this is enough to work on console really is is 25 % part of calculator if you really want to make calculator than know about tkinter and Matplotlip
+ 1
while True:
try:
x = str(input())
x1 = eval(str(x))
print(x + ' = ' + str(x1))
except:
print('error...')
break
#try this u really like my code
+ 1
Hope u like it
+ 1
Soma Mishra can you explain a bit cuz im new to python
+ 1
Tanishq sangwan.....u have to understand that in python oor any programming language....never ever a string concatenate with float
+ 1
So u just have to chance ur print statement in every condition
0
Very nice code!
0
CodeTypes thx
0
Plus I have just got to the function tutorials
0
Yes functions tutorials is so easy to learn because them are so used
0
Yeah, once you understand them they are very useful. They will allow you to get more experienced in python by creating more advanced code.
0
K
0
I'll get through them asap
0
It is in steing value it must be in int value
0
It's like this
https://code.sololearn.com/cRYxD0NH1WCC/?ref=app