Python claculator | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
- 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

2nd Feb 2017, 4:09 AM
Akshay
Akshay - avatar
14 Antworten
+ 11
equation=input() answer=eval(equation) print(answer) #there, a fully functional calculator
2nd Feb 2017, 4:47 AM
Ahri Fox
Ahri Fox - avatar
+ 9
you two need hugs
2nd Feb 2017, 5:12 AM
Ahri Fox
Ahri Fox - avatar
+ 4
it work now? you need to print the answer too
2nd Feb 2017, 4:56 AM
jay
jay - avatar
+ 4
the if is outside the loop?
2nd Feb 2017, 4:59 AM
jay
jay - avatar
+ 4
do Ahri Foxes answer..it is much cleaner and will work no problems
2nd Feb 2017, 5:16 AM
jay
jay - avatar
+ 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 ^^
2nd Feb 2017, 6:52 AM
visph
visph - avatar
+ 3
while(1)... 1 is equal to true. while is always true.. operator is c not a
2nd Feb 2017, 4:16 AM
jay
jay - avatar
+ 3
i told you... 1. while(1) will always be true.. therefore will never exit.. 2. change if a=="add" to if c=="add"
2nd Feb 2017, 4:29 AM
jay
jay - avatar
+ 1
If I write this code ....just it keeps asking for the inputs and doesnot do the calculation.... what is wrong with my code
2nd Feb 2017, 4:24 AM
Akshay
Akshay - avatar
+ 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!!!!
2nd Feb 2017, 4:55 AM
Akshay
Akshay - avatar
+ 1
I did change that add..!!!!
2nd Feb 2017, 4:56 AM
Akshay
Akshay - avatar
+ 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
2nd Feb 2017, 4:58 AM
Akshay
Akshay - avatar
+ 1
Is it outside????how can i include if also within while loop
2nd Feb 2017, 5:00 AM
Akshay
Akshay - avatar
0
Someone explain please
2nd Feb 2017, 5:14 AM
Akshay
Akshay - avatar