Python path/crash problem

Hi all, i have a problem with my python dir. I use VScode as and editor and i can run and debug python easily in there without opening the standard python terminal. But when i want to exactly open python and run a file in there. I’m at the exercise3.1 in the “Scientific computing with Python certification”. When i write the file exactly as instructed and run it in Python, It keeps closing automatically when i type for example 50 and then 10. After typing 10 and clicking enter it closes, without any errors or warnings. I have tried to reinstall python many times and changed my systempathing to different places etc. Yet nothing works. I did see that in VScode, it notified that i should download it through windows store… So i did it and it still does’nt work.
If this can’t be fixed, will it effect the end user if they use my files?

Can anyone help with this?

This is a picture of the Python terminal. This will close after i hit “Enter”.

Could you write in steps what leads to unexpected behavior?

Could you link to specific page/exercise you are following?

Exercise 1.

  1. I have written the code and in the terminal i write “./exercise2_7.py” because i want to open the file in Python.
  2. I type 50 then press Enter.
  3. I type 10 then press Enter.
  4. It closes Python.
    After step 3. it should tell me “Pay: 500”
    But instead it chooses step 4…

Thanks, this clears up some of it.

Generally to run something in python it’s needed to use python interpreter. Usually that’s done by passing file name as an argument to the python interpreter, ie. in terminal:

python3 exercise2_7.py

I guess depending on additional system configuration, it might be possible to make .py file behave as an executable file. Looking at your description and screens it seems something like that is happening. However typing ./exercise2_7.py opens for you new terminal window, which then closes once python script finishes.

If you wish to keep running script like that without new terminal window closing, you might need to somewhat force it to not close on it own. One way could be making script not exist without additional action, for example adding another, blank input() at the end, should keep window open until enter is pressed once more, after seeing the answer.

Thank you, it worked!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.