Python Forum
Python Program Runs in Pycharm but not in Terminal - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Python Program Runs in Pycharm but not in Terminal (/thread-25621.html)



Python Program Runs in Pycharm but not in Terminal - Vbhardwaj2383 - Apr-05-2020

Hi there,

I am 2 days into learning Python (tried a year ago but couldn't continue at that time). So, I am trying to make simple Programs to learn this language and I have written the following program which does very basic of Mathematics. Now, when I run this program in PyCharm I get no error whereas when I am running from a Terminal It's not working as expected.

Another thing is It runs in a Terminal if I copy paste the File in same folder as PyCharm. Here are all the Details:

Code:

num1 = False
num2 = False
operator = True

while type(num1) is not int:
    try:
        num1 = int(input("Enter First Integer: "))
    except ValueError:
        print("Error: Only accepts Integers")
while type(num2) is not int:
    try:
        num2 = int(input("Enter Second Integer: "))
    except ValueError:
        print("Error: Only accepts Integers")

try:
    while operator is True:
        operator = input("Enter an Operator: ")
        if operator == "+":
            result = num1 + num2
            operator = False
        elif operator == "-":
            result = num1 - num2
            operator = False
        elif operator == "*":
            result = num1 * num2
            operator = False
        elif operator == "/":
            result = num1/num2
            operator = False
        else:
            operator = True
            print("Enter a correct Symbol")
    print(result)
except:
    print("Unkown Error")
Snapshot when I run it from Pycharm:
[Image: Khy9fDp]

Snapshot of when I run from Terminal (from a Folder on Desktop)
[Image: sFemgs6]

Snapshot of when I give the Path of Python.exe file of Pycharm Folder and then run the file (It works then):
https://imgur.com/a/UJ39bUL

And it also works if I copy paste the Code File in PyCharm Folder.

I did try changing the PythonPath Home but that didn't fix the issue.

Any guidance on this is appreciated. Thanks !

Regards,


RE: Python Program Runs in Pycharm but not in Terminal - j.crater - Apr-06-2020

Hello and welcome to Python and the forums!

For me your code works fine, either in PyCharm, PyCharm terminal or Windows PowerShell.

I recommend you to rewrite your Except clause, so it will display the specific error that happens (instead of just "unknown" message):

except Exception as e:
    print(e)



RE: Python Program Runs in Pycharm but not in Terminal - Vbhardwaj2383 - Apr-06-2020

Hi,

First of all thank you so much for replying and looking into my problem. I did what you asked but it doesn't help out that much. Please check the following Image. I am running the same program from CMD vs PS and it's giving different results.. Take a look pls and let me know what could be causing this.

[Image: wm84PPJ]