-1

I wrote a factorial program in Sublime text editor. After executing the program using the shortcut key Ctrl + B only the first print statement is getting executed. However, I tried using the shortcut key Ctrl + Shift + B and the result is the same.

The problem is that proper execution is not achieved and I am unable to figure out the issue which is causing the problem.

Here is an image of the above-mentioned situation. As you can clearly see that I am following the conventions to execute the code. However, only the first line is executed.

enter image description here

Although I tried the same code in default Python IDLE I got the result. As such I don't think the code is wrong. Is it due to some IDE issue or have I not installed the sublime text editor properly.

1 Answers1

2

Your code isn't wrong; the problem is that Sublime doesn't support interacting with a running program without extra work. Although it connects stdout and stderr to the output panel so that output your program generates can be displayed, it doesn't connect stdin to anything.

What you see is yourself typing 34 into the output panel, but your program doesn't see that and just sits in the background forever waiting for input that you can't provide until you kill it.

In order to run an interactive program like this from Sublime, you need to create your own sublime-build file that either opens an external terminal and runs the program there, or one that utilizes a package such as Terminus to open a terminal within Sublime and run the program there. Both of those require you to know what command you need to run in the terminal in order to run your program in order to set up the build.

An example of using Terminus for this task (using C and not Python, so you'd need to adapt it) can be found in this video on buffering and interactive builds in Sublime (disclaimer, I'm the author).

OdatNurd
  • 21,371
  • 3
  • 50
  • 68