-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathintro.tex
More file actions
38 lines (33 loc) · 1.89 KB
/
intro.tex
File metadata and controls
38 lines (33 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
The first chapter of the book the book ``Introduction to Scientific Programming in Python''
does not contain much programming, but is inteded to get people started by writing
and running a very small Python program. The exercises included here serve the same
purpose. The programming itself is trivial, but if you are new to Python and programming
these exercises are very to verify that you have installed the necessary tools
and that they are working correctly.
\begin{Problem}{\textbf{Write a Hello, World! program}} \label{hello}
%\addcontentsline{toc}{section}{Exercise 1.1: Throw a ball - \texttt{ball.py}}
\noindent Write a Python program that prints the words "Hello, World!" to the
screen. Save the program in a file $\texttt{hello.py}$ and run it from
the terminal, or from an IDE (such as Spyder) if you prefer. Verify that the
expected output is printed in the terminal
Filename: $\texttt{hello.py}$
\end{Problem}
\begin{Problem}{\textbf{Check your Python version}} \label{version}
%\addcontentsline{toc}{section}{Exercise 1.1: Throw a ball - \texttt{ball.py}}
\noindent Open a terminal window, for instance \py{Terminal} on MacOS or
\py{Powershell} on Windows. Type the words
\begin{python}
python --version
\end{python}
in the terminal. You should then see your Python version printed in the terminal,
most likely Python $3.7.x$, where $x$ is some number. Next, simply type
\begin{python}
python
\end{python}
in the same terminal window. This will open an \emph{interactive Python session}.
Your Python version is again displayed first, followed by a special prompt where
you can type Python commands. Try to type a simple mathematical expression such as
\py{2+2} and press return. The type the line \py{print("Hello!")} and press
return. Verify that it works as expected, and look for typos in the line you wrote if
you get an error message. Finally, write \py{quit()} or \py{exit()} to end the session.
\end{Problem}