Why is this code running absolutely fine on Idle but not on Pycharm ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why is this code running absolutely fine on Idle but not on Pycharm ?

https://code.sololearn.com/cbbkvxpSSSM1/?ref=app

5th Apr 2019, 11:31 AM
Manish Kumar
Manish Kumar - avatar
25 Answers
+ 11
OK I see. So the exception handling bugs on the Linux pycharm. Strange...
5th Apr 2019, 12:45 PM
Cépagrave
Cépagrave - avatar
+ 10
'A' can't be converted to float, it's not a number.
5th Apr 2019, 12:32 PM
Cépagrave
Cépagrave - avatar
+ 10
So a simple code like this: try: float('a' ) except ValueError: print('error') Shouldn't work. Can you try this?
5th Apr 2019, 12:53 PM
Cépagrave
Cépagrave - avatar
+ 10
OK. I already can give you this advice: pycharm is a very heavy machine. I also had bugs with it. Some of them unsolved. So unless you really need pycharm and its million functionalities, you may be happy and running with 'sublime text 3' (as I do).
5th Apr 2019, 1:15 PM
Cépagrave
Cépagrave - avatar
+ 10
Look at Flandre Scarlet 's answer. I missed that. Your code is wrong when' add' case is chosen. And that's where the bug comes from.
5th Apr 2019, 2:09 PM
Cépagrave
Cépagrave - avatar
+ 10
Oh wait, the first error you posted was with 'div' choice. So there still may be a pycharm bug. You should correct your script and see if it still bugs then.
5th Apr 2019, 2:12 PM
Cépagrave
Cépagrave - avatar
+ 10
Difficult to understand what happens here. I re-installed Pycharm on my linux laptop, so it's the 2019.1 version too. Then pasted my corrected version of your code in it, and it always works fine. Your error is a mystery to me. If you want to work on ide, you can keep on with idle, but i also suggest Geany, it's much lighter than pycharm, and executes your files by launching a terminal. About SublimeText, its embedded console is limited, and for this code it won't be able to take the successive inputs (which may have been the reason why you uninstalled it). But you can keep a terminal on the side and launch your files from there. Once you get used to this, it's really fine.
5th Apr 2019, 10:58 PM
Cépagrave
Cépagrave - avatar
+ 9
If you just try : float("A") You'll see the same error.
5th Apr 2019, 12:34 PM
Cépagrave
Cépagrave - avatar
+ 9
I saw your screenshot. But seems to be on windows. Does this work fine on Linux ?
5th Apr 2019, 1:07 PM
Cépagrave
Cépagrave - avatar
+ 9
I corrected your file. Look at the changes at line 20 https://code.sololearn.com/cLPNULkOxapi/?ref=app
5th Apr 2019, 2:57 PM
Cépagrave
Cépagrave - avatar
+ 8
I've just checked it on pycharm community 2018.2 on my windows pc, it works fine. Your problem may come from your pycharm settings.
5th Apr 2019, 11:38 AM
Cépagrave
Cépagrave - avatar
+ 8
Well, from the error message you got, it seems you entered 'A' as the second number, which your code tries to turn into a float. If this is what you typed, then it's normal you get an error.
5th Apr 2019, 12:29 PM
Cépagrave
Cépagrave - avatar
+ 8
Sure, with adequate numbers, your code will work. There was a problem with your input, not with your code 😊
5th Apr 2019, 12:36 PM
Cépagrave
Cépagrave - avatar
+ 8
Why you're printing float(a) + float(b) when your inputs are stored in x and y?😂
5th Apr 2019, 1:34 PM
Flandre Scarlet
Flandre Scarlet - avatar
+ 2
Cépagrave https://drive.google.com/file/d/1i6CrKmIakLTU5vGQT1YIoCma-N4vAgs7/view?usp=sharing i uninstalled sublime text 3same day i installed thst on my machine because i faced similar issues. Code was working fine on idle but not on ST3(on linux). ~ swim ~ yeah bro, u r right.
5th Apr 2019, 2:06 PM
Manish Kumar
Manish Kumar - avatar
+ 1
Cépagrave, I am getting the following on pycharm 2019.1 community : *************************WELCOME*************************** ENTER 'ADD' FOR ADDITION. ENTER 'SUB' FOR SUBTRACTION. ENTER 'MUL' FOR MULTIPLICATION ENTER 'DIV' FOR DIVISION. ENTER 'QUIT' TO END/EXIT THE PROGRAM. ENTER ANY OF THE OPTIONS : DIV ENTER A NUMBER : 45 ENTER ANOTHER NUMBER : A Traceback (most recent call last): File "/root/PycharmProjects/simple-calculator/calcc.py", line 32, in <module> y = float(input('ENTER ANOTHER NUMBER : ')) ValueError: could not convert string to float: 'A' Process finished with exit code 1
5th Apr 2019, 11:43 AM
Manish Kumar
Manish Kumar - avatar
+ 1
oh yeah, its also working fine on pycharm running on windows machine.
5th Apr 2019, 12:12 PM
Manish Kumar
Manish Kumar - avatar
+ 1
Will try that out later & let u know.
5th Apr 2019, 1:08 PM
Manish Kumar
Manish Kumar - avatar
0
Yeah 'A' was the second number
5th Apr 2019, 12:30 PM
Manish Kumar
Manish Kumar - avatar