- 1
Python claculator
while (1): a=int (input ("number1")) b=int (input ("num2")) c=input ("enter operator") if a=="add": e=a+b here the while loop continues for ever....It takes only the input infinite times and doesnot do the calculation.....where am I going wrong
14 Réponses
+ 11
equation=input()
answer=eval(equation)
print(answer)
#there, a fully functional calculator
+ 9
you two need hugs
+ 4
it work now? you need to print the answer too
+ 4
the if is outside the loop?
+ 4
do Ahri Foxes answer..it is much cleaner and will work no problems
+ 4
Hey! Your code don't work simply because you don't perform the good comparison :P
Look at the condtion of your 'if' statement: a=='add' but you need to c=='add', anyway else the condition is always false ^^
+ 3
while(1)... 1 is equal to true. while is always true.. operator is c not a
+ 3
i told you... 1. while(1) will always be true.. therefore will never exit.. 2. change if a=="add" to if c=="add"
+ 1
If I write this code ....just it keeps asking for the inputs and doesnot do the calculation.... what is wrong with my code
+ 1
I understood what u said Jay ....but my question is why does while loop not perform the calculation....It keeps asking for the variables only.....I have written if also in a indented way right...I want to do a infinite loop only!!so it wrote 1!!!!
+ 1
I did change that add..!!!!
+ 1
I wrote print also.....my question is.....like why does the while infinite loop apply only to getting of variables .....and not perform calculation.....when I remove while loop the calculator works fine
+ 1
Is it outside????how can i include if also within while loop
0
Someone explain please