Skip to content

Commit 64cd27b

Browse files
committed
first python program added
1 parent 41ebb34 commit 64cd27b

19 files changed

+194
-16
lines changed

make.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ rm -rf "$currentDir/website" || true
2222
echo "$(date +'%0Y-%0m-%0d %0R:%0S'): We setup a virtual environment in a temp directory."
2323
tempDir="$(mktemp -d)"
2424
echo "$(date +'%0Y-%0m-%0d %0R:%0S'): Got temp dir '$tempDir', now creating environment in it."
25-
python3 -m venv "$tempDir"
25+
python3 -m venv --system-site-packages "$tempDir"
2626
echo "$(date +'%0Y-%0m-%0d %0R:%0S'): Activating virtual environment in '$tempDir'."
2727
. "$tempDir/bin/activate"
2828
export PYTHON_INTERPRETER="$tempDir/bin/python3"

notation/software.sty

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ Learn more at \url{https://scipy.org}.}
106106
name={\softwareStyle{SimPy}},
107107
sort={SimPY},
108108
description={is a \python\ library for discrete event simulation~\cite{Z2024DESIEWS}. %
109-
Learn more at \url{https://simpy.readthedocs.io.}
109+
Learn more at \url{https://simpy.readthedocs.io}.}
110110
}%
111111
\protected\gdef\simpy{\pgls{simpy}}%
112112
%

notation/sources.sty

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,12 @@
55
\xdef\programmingWithPythonRepo{https://github.com/thomasWeise/programmingWithPython}%
66
\xdef\programmingWithPythonUrl{https://thomasweise.github.io/programmingWithPython}%
77
%
8-
8+
\xdef\programmingWithPythonCodeRepo{https://github.com/thomasWeise/programmingWithPythonCode}%
9+
%
10+
%%% Print some example code
11+
%% #1 the path
12+
%% #2 the arguments
13+
%% #3 the label
14+
%% #4 the caption
15+
\protected\gdef\exCode#1#2#3#4{\expandafter\gitPython{\programmingWithPythonCodeRepo}{#1}{#2}{#3}{#4}}%
16+
%

styles/floats.sty

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@
1010
\mbox{\fcolorbox{black}{listing-background}{\mbox{#1}}}%
1111
\egroup}%
1212
%
13+
\RequirePackage{placeins}%
14+
%

styles/keys.sty

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
%
55
\RequirePackage[os=win]{menukeys}%
66
\renewmenumacro{\keys}[+]{shadowedroundedkeys}%
7+
\renewmenumacro{\directory}[/]{hyphenatepaths}%
78
%
89
%% see https://tex.stackexchange.com/questions/387952
910
\RequirePackage{fontawesome}%
@@ -13,3 +14,7 @@
1314
%
1415
\protected\gdef\ubuntuTerminal{\keys{\ctrl+\Alt+T}}%
1516
\protected\gdef\windowsTerminal{press \keys{\OSwin + R}, type in \bashil{cmd}, and hit \keys{\return}}%
17+
%
18+
%% the main menu key
19+
\protected\gdef\pycharmMainMenu{\ensuremath{\mathrel{\rlap{\raisebox{\fontdimen22\textfont2}{\ensuremath{=}}}\raisebox{-0.5\fontdimen22\textfont2}{\ensuremath{=}}}}}
20+
%
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
\hsection{Our First Program}%
2+
\FloatBarrier%
3+
%
4+
We now want to write and execute our very first \python\ program.
5+
This program should just print \inQuotes{Hello World!} to the text output and then exit.
6+
It therefore will consist of the single statement \pythonil{print("Hello World!")}, as illustrated in \cref{lst:very_first_program}.
7+
8+
\exCode{00_veryFirstProject/very_first_program.py}{--args format}{very_first_program}{%
9+
Our very first \python\ program, which just prints \inQuotes{Hello World!}}%
10+
%
11+
\begin{figure}%
12+
\centering%
13+
%
14+
\subfloat[][%
15+
Creating a new project in \pycharm, step~1: click \menu{New Project}.%
16+
\label{fig:firstProgram01createPycharmProject}%
17+
]{\tightbox{\includegraphics[width=0.47\linewidth]{\currentDir/firstProgram01createPycharmProject}}}%
18+
%
19+
\strut\hfill\strut%
20+
%
21+
\subfloat[][%
22+
Creating a new project in \pycharm, step~2: Make sure that \menu{Pure Python} is selected in the left pane, then select a name for the project (here: \directory{00\_veryFirstProject}), a directory location (some path on my \ubuntu\ machine, you will pick some other directory), and we select the current \python\ installation as \menu{Custom Environment}. %
23+
We finally click \menu{Create}.%
24+
\label{fig:firstProgram02createPycharmProject}%
25+
]{\tightbox{\includegraphics[width=0.47\linewidth]{\currentDir/firstProgram02createPycharmProject}}}%
26+
%
27+
\\[10pt]%
28+
%
29+
\subfloat[][%
30+
The new and empty project has been created.%
31+
\label{fig:firstProgram03pycharmProjectCreated}%
32+
]{\tightbox{\includegraphics[width=0.775\linewidth]{\currentDir/firstProgram03pycharmProjectCreated}}}%
33+
%
34+
\\[10pt]%
35+
%
36+
\subfloat[][%
37+
We create a new \python\ file within this project by right-clicking on the project folder \directory{00\_veryFirstProject} and selecting \menu{New>Python File}.%
38+
\label{fig:firstProgram04createPythonFile}%
39+
]{\tightbox{\includegraphics[width=0.775\linewidth,trim={0 200 0 0},clip]{\currentDir/firstProgram04createPythonFile}}}%
40+
%
41+
\caption{The steps to create a new \python\ file in a new \pycharm\ project and to then run it (\ubuntu).}%
42+
\label{fig:veryFirstProgramA}%
43+
\end{figure}
44+
%
45+
\begin{figure}%
46+
\ContinuedFloat%
47+
\centering%
48+
%
49+
\subfloat[][%
50+
We enter a name for the new \python\ file (here:~\directory{very\_first\_program}) and hit \keys{\enter}.%
51+
\label{fig:firstProgram05createPythonFile}%
52+
]{\tightbox{\includegraphics[width=0.775\linewidth]{\currentDir/firstProgram05createPythonFile}}}%
53+
%
54+
\\[10pt]%
55+
%
56+
\subfloat[][%
57+
The new and empty file \directory{very\_first\_program.py} has been created in the project \directory{00\_veryFirstProject}.%
58+
\label{fig:firstProgram06pythonFileCreated}%
59+
]{\tightbox{\includegraphics[width=0.775\linewidth]{\currentDir/firstProgram06pythonFileCreated}}}%
60+
%
61+
\\[10pt]%
62+
%
63+
\subfloat[][%
64+
We enter the text from \cref{lst:very_first_program}. \pycharm\ automatically saves it.%
65+
\label{fig:firstProgram07writeHelloWorld}%
66+
]{\tightbox{\includegraphics[width=0.775\linewidth]{\currentDir/firstProgram07writeHelloWorld}}}%
67+
%
68+
%
69+
\caption{The steps to create a new \python\ file in a new \pycharm\ project and to then run it (\ubuntu).}%
70+
\label{fig:veryFirstProgramB}%
71+
\centering%
72+
%
73+
\end{figure}%
74+
%
75+
\begin{figure}%
76+
\ContinuedFloat%
77+
\centering%
78+
%
79+
\subfloat[][%
80+
In order to run this program, we right-click on the program file in the tree view and select \menu{Run `very\_first\_program'}. %
81+
Alternatively, we could press \keys{\ctrl+\shift+F10}.%
82+
\label{fig:firstProgram08runProgram}%
83+
]{\tightbox{\includegraphics[width=0.775\linewidth,trim={0 200px 0 0},clip]{\currentDir/firstProgram08runProgram}}}%
84+
%
85+
\\[10pt]%
86+
%
87+
\subfloat[][%
88+
And indeed, in the console pane at the bottom of the \pycharm\ window, the text \inQuotes{Hello World!} appears.%
89+
\label{fig:firstProgram09programResult}%
90+
]{\tightbox{\includegraphics[width=0.775\linewidth]{\currentDir/firstProgram09programResult}}}%
91+
%
92+
\caption{The steps to create a new \python\ file in a new \pycharm\ project and to then run it (\ubuntu).}%
93+
\label{fig:veryFirstProgramC}%
94+
\centering%
95+
%
96+
\end{figure}%
97+
98+
In \pycharm, we usually will not just create a single \python\ source code file.
99+
Instead, we will work in the context of \emph{projects}, which can contain many \python\ files, settings, build scripts, and other resources.
100+
Inside such a project, we would create the \python\ file, write our source code from \cref{lst:very_first_program} into it, and then run it.
101+
The steps for doing this are illustrated with screenshots in \cref{fig:veryFirstProgramA}, which were taken on my \ubuntu\ machine.
102+
On \windows, this will look very similar (maybe with the exception of ``\verb=\='' instead of ``\verb=/='' as directory separator characters in paths).
103+
104+
Since we started with a completely new \pycharm\ installation in \cref{sec:installingPyCharm}, no project has yet been created.
105+
So when we open \pycharm, we will arrive at the project creation screen illustrated in \cref{fig:firstProgram01createPycharmProject}.
106+
Here, we will \menu{New Project}, which takes us to the second project creation screen shown in \cref{fig:firstProgram02createPycharmProject}.
107+
In case that you already had \pycharm\ installed and already created some projects in the past, you can get to the same screen by clicking \menu{\pycharmMainMenu > File > New Project}.
108+
Either way, when arriving at the screen, you will find several confusingly looking options.
109+
First, make sure that \menu{Pure Python} is selected in the left pane.
110+
Then you can choose a name for the project in the \menu{Name:} text box.
111+
For the sake of our example, let's call the new project \directory{00\_veryFirstProject}.
112+
113+
Below the name text box, you can select the destination directory in which the project folder should be created in the \menu{Location:} box.
114+
You can ignore the text in the screenshot, as this is just the path that I am using on my \ubuntu\ machine.
115+
Instead, you will choose some suitable directory on your computer.
116+
(Notice that in \windows, the directory separator character is ``\verb=\='' and not ``\verb=/='' as on my \ubuntu\ \linux.)
117+
Either way, on my machine, I choose the rather elaborate path \directory{home/tweise/local/programming/python/programmingWithPythonCode}.
118+
\pycharm\ will create the folder \directory{00\_veryFirstProject} for our new project \emph{inside} this directory.
119+
But, as said, you will choose some other suitable place on your computer.
120+
121+
The following options may not make any sense for you, which is totally OK for now.
122+
Please make sure to select \menu{Interpreter Type: > Custom Environment} as well as \menu{Environment: > Select existing} and \menu{Type: > Python}.
123+
Under \menu{Python Path:}, you would choose the \python\ interpreter you have installed on your system (see \cref{sec:installingPython}).
124+
On my system that was \inQuotes{\python~3.10.12} at the time of this writing.
125+
We finally click \menu{Create}.
126+
We now have created our first and empty \pycharm\ \python\ project -- as illustrated in \cref{fig:firstProgram03pycharmProjectCreated}.
127+
128+
We can now create the \python\ file to write our actual program code.
129+
To do this, we right-click on the folder \directory{00\_veryFirstProject} in our \menu{Project} tree view pane on the left-hand side (see \cref{fig:firstProgram04createPythonFile}).
130+
In the menu that pops up, we select and click \menu{New > Python File}.
131+
This takes us the \menu{New Python file} creation dialog illustrated in \cref{fig:firstProgram05createPythonFile}.
132+
Here, we enter the name for our first program.
133+
What could be more fitting than \directory{very\_first\_program}?
134+
After hitting \keys{Enter}, the file is created in our project folder and opened in the editor pane, as shown in \cref{fig:firstProgram06pythonFileCreated}.
135+
136+
We now enter the single line of code from \cref{lst:very_first_program} into the editor, as illustrated in \cref{fig:firstProgram07writeHelloWorld}.
137+
We do not need to save the file, as \pycharm\ does this automatically for us.
138+
139+
Finally, we want to actually execute, i.e., run, our program.
140+
We can do this directly from the editor by pressing \keys{\ctrl + \shift + F10}.
141+
We can also do it by right-clicking on the file in the project tree view on the left-hand side and then clicking \menu{Run `very\_first\_program'} in the popup menu, as shown in \cref{fig:firstProgram08runProgram}.
142+
143+
Either way, a console with the title \inQuotes{very\_first\_program} opens at the bottom of our editor.
144+
And behold:
145+
Indeed, the text \bashil{Hello World!} appears.
146+
147+
Well, before that text, we see the command line that was actually executed, namely the \python\ interpreter with our file's path as parameter.
148+
And after our program's output, we are notified that \inQuotes{Process finished with exit code 0,} which means that the program has completed successfully and without error.
149+
150+
Congratulations.
151+
You now have written, saved, and executed your first ever \python\ program!%
152+
%
153+
\endhsection%
154+
%
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading

text/main/basics/gettingStarted/gettingStarted.tex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
%
2727
\hinput{installingPython}{installingPython}%
2828
\hinput{installingPyCharm}{installingPyCharm}%
29+
\clearpage%
30+
\hinput{firstProgram}{firstProgram}%
2931
%
3032
\endhsection%
3133
%

text/main/basics/gettingStarted/installingPyCharm/installingPyCharm.tex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
The installation guide for \pycharm\ can be found at \url{https://www.jetbrains.com/help/pycharm/installation-guide.html}.%
99
%
1010
\hinput{installingPyCharmWindows}{installingPyCharmWindows}%
11+
\FloatBarrier%
1112
\hinput{installingPyCharmUbuntu}{installingPyCharmUbuntu}%
12-
\afterpage{\clearpage}%
13+
\FloatBarrier%
1314
\endhsection%
1415
%

text/main/basics/gettingStarted/installingPyCharm/installingPyCharmWindows/installingPyCharmWindows.tex

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,12 @@
3030
\label{fig:installingPyCharmWindows04download}%
3131
]{\tightbox{\includegraphics[width=0.47\linewidth]{\currentDir/installingPyCharmWindows04download}}}%
3232
%
33-
\\[10pt]%
33+
\caption{The installation steps of \pycharm\ under \windows.}%
34+
\label{fig:installingPyCharmWindowsA}%
35+
%
36+
\end{figure}%
37+
\begin{figure}%
38+
\ContinuedFloat%
3439
%
3540
\subfloat[][%
3641
The download is completed. We click \keys{Open file}.%
@@ -59,14 +64,7 @@
5964
]{\tightbox{\includegraphics[height=3.75cm]{\currentDir/installingPyCharmWindows08runInstaller}}}%
6065
\hfill\strut%
6166
%
62-
\caption{The installation steps of \pycharm\ under \windows.}%
63-
\label{fig:installingPyCharmWindowsA}%
64-
%
65-
\end{figure}%
66-
%
67-
\begin{figure}%
68-
\ContinuedFloat%
69-
\centering%
67+
\\[10pt]%
7068
%
7169
\subfloat[][%
7270
The welcome screen of the installer. We click \keys{Next}.%
@@ -108,7 +106,14 @@
108106
\label{fig:installingPyCharmWindows14installation}%
109107
]{\tightbox{\includegraphics[height=4cm]{\currentDir/installingPyCharmWindows14installation}}}%
110108
%
111-
\\[10pt]%
109+
\caption{The installation steps of \pycharm\ under \windows.}%
110+
\label{fig:installingPyCharmWindowsB}%
111+
%
112+
\end{figure}%
113+
%
114+
\begin{figure}%
115+
\ContinuedFloat%
116+
\centering%
112117
%
113118
\strut\hfill\strut%
114119
\subfloat[][%
@@ -141,7 +146,7 @@
141146
\strut\hfill\strut%
142147
%
143148
\caption[]{The installation steps of \pycharm\ under \windows.}%
144-
\label{fig:installingPyCharmWindowsB}%
149+
\label{fig:installingPyCharmWindowsC}%
145150
\end{figure}%
146151
%
147152
The process of installing \pycharm\ under \windows\ is illustrated in \cref{fig:installingPyCharmWindowsA}.

text/main/basics/gettingStarted/installingPython/installingPython.tex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
\end{itemize}%
1414
%
1515
\hinput{installingPythonWindows}{installingPythonWindows}%
16+
\FloatBarrier%
1617
\hinput{pythonUnderUbuntu}{pythonUnderUbuntu}%
17-
\afterpage{\clearpage}%
18+
\FloatBarrier%
1819
%
1920
\endhsection%
2021
%

0 commit comments

Comments
 (0)