1
00:00:00,210 --> 00:00:06,900
Previously, you learned that to execute a Python program in Visual Studio Code, you can either use the 'Run'

2
00:00:06,900 --> 00:00:15,000
button or type in the command manually in here, such as python3.9 or python3.10

3
00:00:15,000 --> 00:00:21,210
or python3.8, depending on what version of Python you have.
If you are on Windows...

4
00:00:21,210 --> 00:00:28,650
So that was for Mac and Linux. On Windows, that'd be python3.9 and then that would be followed by

5
00:00:28,650 --> 00:00:29,980
the name of the file.

6
00:00:31,590 --> 00:00:32,880
In this case, 

7
00:00:32,880 --> 00:00:33,540
basics.py..

8
00:00:33,660 --> 00:00:35,690
So that file that contains the code.

9
00:00:36,060 --> 00:00:44,550
But what happens if you delete the name of the file and executes only the first part of the command?

10
00:00:45,390 --> 00:00:46,170
This would happen.

11
00:00:46,560 --> 00:00:54,690
So when you don't apply a file to the python command, python will open in an on-demand mode.

12
00:00:55,110 --> 00:01:02,460
This is also known as the python interactive shell or just the python shell for short or the python

13
00:01:02,460 --> 00:01:03,120
console.

14
00:01:03,270 --> 00:01:07,770
So different names for this on-demand Python interpreter.

15
00:01:07,950 --> 00:01:12,030
This interactive shell expects python codes directly.

16
00:01:12,420 --> 00:01:19,980
So all you have to do is write the code 24 times seven, for example, and press enter and you get the

17
00:01:19,980 --> 00:01:21,060
output instantly.

18
00:01:21,460 --> 00:01:29,250
And so the purpose of this python shell is to give programmers a quick interpreter useful for testing

19
00:01:29,250 --> 00:01:31,550
things out and playing around with the code.

20
00:01:32,070 --> 00:01:39,270
For example, while we write this program that calculates the amount of hours in a week, we may not

21
00:01:39,270 --> 00:01:43,120
be sure about certain features what we need to use.

22
00:01:43,260 --> 00:01:50,670
For example, we don't know whether to use an asterisk or a plus for the multiplication operation.

23
00:01:51,030 --> 00:01:57,060
So in that case, we would open the python shell just as I did in here and try things out.

24
00:01:57,070 --> 00:02:05,190
So is the asterisk a multiplication operator or is the plus what we are looking for?

25
00:02:05,430 --> 00:02:08,010
And you see that this doesn't make much sense.

26
00:02:08,040 --> 00:02:13,850
So it looks like we have an addition operator here and a multiplication operator here.

27
00:02:13,980 --> 00:02:18,410
So then we go ahead and write that in our Python file in our program.

28
00:02:18,900 --> 00:02:26,040
Of course, this was a very 'dumb' example because we all know that the plus is for additional operations

29
00:02:26,040 --> 00:02:26,460
and so on.

30
00:02:26,460 --> 00:02:34,560
But in more complex programs, you have to try things out to see what works and what doesn't work here

31
00:02:34,560 --> 00:02:38,010
in the interactive shell in a quick fashion and then

32
00:02:38,030 --> 00:02:40,610
write that code in the python file.

33
00:02:40,800 --> 00:02:44,970
So that is the advantage of the python shell quick programming.

34
00:02:45,240 --> 00:02:51,420
The disadvantage is that the code you write in the python shell cannot be saved.

35
00:02:51,720 --> 00:02:58,200
So if you close Visual Studio Code now and you open Visual Studio Code again, this code here

36
00:02:58,200 --> 00:03:04,500
has disappeared, the shell will close, this session will close, and you will not see the code anymore.

37
00:03:04,950 --> 00:03:11,670
In contrast, you can save the code in dot py files because they are files saved in disks.

38
00:03:12,330 --> 00:03:19,470
Therefore, the conclusion here is that the python shell is for testing things out and .py files are

39
00:03:19,470 --> 00:03:21,690
for writing complete programs.

40
00:03:22,500 --> 00:03:25,450
Now I want to give you a pro tip before I close this video.

41
00:03:25,920 --> 00:03:33,090
I don't know if my computer has a calculator app or not, and that is not because I never needed to

42
00:03:33,090 --> 00:03:41,340
use a calculator, but because I never look to see if my computer has a calculator because I use Python

43
00:03:41,340 --> 00:03:43,230
as a calculator. Specifically,

44
00:03:43,230 --> 00:03:49,470
what I use actually is that interactive shell and I don't open the interactive shell through

45
00:03:49,470 --> 00:03:57,360
Visual Studio Code, but through the computer terminal on Windows that is called cmd.

46
00:03:57,360 --> 00:03:59,400
So you should go to search.

47
00:04:01,110 --> 00:04:05,040
Look for cmd or the command prompt, open that.

48
00:04:05,070 --> 00:04:11,760
Write py-3.9, or 3.10, whatever interpreter you are using,

49
00:04:12,060 --> 00:04:12,780
execute.

50
00:04:13,350 --> 00:04:18,530
And then you can start using Python as a calculator.
On Mac you would use

51
00:04:18,540 --> 00:04:25,860
of course, python3.9, the command and you'd search for terminal amoung your programs,

52
00:04:25,860 --> 00:04:26,870
not cmd.

53
00:04:27,300 --> 00:04:29,350
That is the case for Linux users as well.

54
00:04:29,580 --> 00:04:34,980
So then here you can use Python, just as we did here in Visual Studio Code.

55
00:04:34,980 --> 00:04:43,020
And actually, it would make more sense to use the interactive shell for the program that we built instead

56
00:04:43,020 --> 00:04:44,950
of writing the program in here.

57
00:04:45,240 --> 00:04:51,360
So we wanted to know how many hours are in a week and you can just use the shell for that because you're

58
00:04:51,360 --> 00:04:56,160
not building an application that is going to be used multiple times.

59
00:04:56,430 --> 00:05:00,870
So this is just a computer program that calculates something.

60
00:05:01,620 --> 00:05:07,470
Of course, that's not a clear distinction between programs and applications, but if there is one,

61
00:05:07,680 --> 00:05:16,400
it is that applications are supposed to be used many times by users and programs can be throw away scripts.

62
00:05:16,920 --> 00:05:18,540
So this is more like a program.

63
00:05:18,960 --> 00:05:24,270
And throughout the course, we will build 10 programs which look more like applications.

64
00:05:24,570 --> 00:05:27,600
And that's about the Python interactive shell.

65
00:05:28,050 --> 00:05:36,660
One warning you should be aware of is that if you run your program now while the interactive shell is

66
00:05:36,660 --> 00:05:39,180
open, see what's going to happen.

67
00:05:39,600 --> 00:05:41,250
I press the 'Run' button.

68
00:05:42,790 --> 00:05:50,650
We get the output's, so this comes from this program, but be aware that if you open an interactive

69
00:05:50,650 --> 00:05:52,960
shell in this terminal now,

70
00:05:58,550 --> 00:06:05,360
and then you run the program again, you're going to get an error because what Visual Studio Code is

71
00:06:05,360 --> 00:06:09,910
trying to do is that it is sending the Windows commands,

72
00:06:09,920 --> 00:06:16,390
so the Python interpreter path and the file path of basics.py.

73
00:06:17,330 --> 00:06:22,630
So these are commands supposed to to go to the Windows command line.

74
00:06:23,000 --> 00:06:27,620
But this one here is the Python interactive shell and this expects Python code.

75
00:06:27,830 --> 00:06:29,360
But this is not Python code.

76
00:06:29,930 --> 00:06:35,230
That's why we get this python error because python is confused with this code.

77
00:06:35,900 --> 00:06:37,080
So it's a syntax error.

78
00:06:37,460 --> 00:06:42,110
Therefore, if you see this error, what you should do is you should exit

79
00:06:44,350 --> 00:06:52,000
the python shell with this command, it's a python function that exits the interactive shell or a program

80
00:06:52,000 --> 00:07:00,130
in case you use it in a dot py file, execute that and you are back to the terminal and here you can

81
00:07:01,350 --> 00:07:03,890
executes that program again.

82
00:07:05,530 --> 00:07:11,530
Now, if you look here, you'll see that we have 
two terminals actually. This one is the one we were

83
00:07:11,530 --> 00:07:16,030
using, but then when you execute that, a new terminal is created.

84
00:07:16,060 --> 00:07:20,310
So this one was created and then here in this terminal,

85
00:07:20,650 --> 00:07:23,610
we opened the python shell with that.

86
00:07:23,980 --> 00:07:27,730
And then when you execute the program, this terminal, it will be used again

87
00:07:29,180 --> 00:07:37,000
by Visual Studio Code, therefore, a trick you could do is that... 
Let me delete these two terminals

88
00:07:37,010 --> 00:07:38,330
so I have nothing here.

89
00:07:38,720 --> 00:07:44,930
What you could do is to use one terminal to run the dot py files.

90
00:07:45,380 --> 00:07:54,020
So this one here, you run it, you run it, and then create a new terminal by using this, so split terminal and you're

91
00:07:54,020 --> 00:07:57,200
going to get two terminals.

92
00:07:57,470 --> 00:08:06,580
In one, you keep a python interactive shell open, and the other you use it to see the output of your dot py files.

93
00:08:06,950 --> 00:08:08,150
So you execute that.

94
00:08:08,540 --> 00:08:14,130
You get the output here and this one here, you use it for your own testing.

95
00:08:15,470 --> 00:08:22,400
Again, if you click that button, the output is going to always display in this terminal.

96
00:08:24,110 --> 00:08:28,260
And with that, thanks a lot for following this video and I'll see you in the next one.

