Python Forum
Python Program Runs in Pycharm but not in Terminal
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python Program Runs in Pycharm but not in Terminal
#1
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,
Reply
#2
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)
Reply
#3
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]
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to do 100 runs simulation based on the current codes? dududada 6 900 Sep-03-2023, 01:43 PM
Last Post: deanhystad
  invoking python in Terminal Euler 2 591 Aug-25-2023, 06:17 AM
Last Post: perfringo
  Launch Python IDLE Shell from terminal Pavel_47 5 1,143 Feb-17-2023, 02:53 PM
Last Post: Pavel_47
  Python VS Code: using print command twice but not getting output from terminal kdx264 4 1,033 Jan-16-2023, 07:38 PM
Last Post: Skaperen
  Another program runs bho68 7 1,143 Nov-08-2022, 08:16 PM
Last Post: bho68
  Can't update new python version on Pycharm GOKUUUU 6 3,700 Jul-23-2022, 09:24 PM
Last Post: GOKUUUU
  UnicodeEncodeError caused by print when program runs from Popen SheeppOSU 5 2,845 Jan-13-2022, 08:11 AM
Last Post: SheeppOSU
  How to use GPU in Python or Pycharm? plumberpy 2 12,912 Oct-11-2021, 12:57 PM
Last Post: plumberpy
  Cannot install tensorflow, numpy etc in Pycharm with Python 3.10 plumberpy 2 3,386 Oct-07-2021, 05:33 AM
Last Post: plumberpy
  Module which run in PyCharm but not as exe or terminal. diegoctn 3 6,443 Jul-13-2021, 04:03 AM
Last Post: Harshith

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020