1.2 A Python Program with Variables
11
The documentation for Spyder 8 might be useful to you. Also, more information
on writing and running Python programs is found in Appendix A.4 herein.
Why not a pocket calculator instead?
Certainly, finding the answer as with the program above could easily have
been done with a pocket calculator. No objections to that and no programming
would have been needed. However, what if you would like to have the position
of the ball for every milli-second of the flight? All that punching on the
calculator would have taken you something like 4 h!
If you know how to program, however, you could modify the code above
slightly, using a minute or two of writing, and easily get all the positions
computed in one go within a second.
An even stronger argument, however, is that mathematical models from
real life are often complicated and comprehensive. The pocket calculator
cannot cope with such problems, even not the programmable ones, because
their computational power and their programming tools are far too weak
compared to what a real computer can offer.
Write programs with a text editor
When Python interprets some code in a file, it is concerned with every
character in the file, exactly as it was typed in. This makes it troublesome to write the code into a file with word processors like, e.g., Microsoft Word, since such a program will insert extra characters, invisible
to us, with information on how to format the text (e.g., the font size and
type).
Such extra information is necessary for the text to be nicely formatted
for the human eye. Python, however, will be much annoyed by the extra
characters in the file inserted by a word processor. Therefore, it is fundamental
that you write your program in a text editor where what you type on the
keyboard is exactly the characters that appear in the file and what Python
will later read. There are many text editors around. Some are stand-alone
programs like Emacs, Vim, Gedit, Notepad++, and TextWrangler. Others
are integrated in graphical development environments for Python, such as
Spyder.
8 See, e.g., https://www.spyder-ide.org/.
11
The documentation for Spyder 8 might be useful to you. Also, more information
on writing and running Python programs is found in Appendix A.4 herein.
Why not a pocket calculator instead?
Certainly, finding the answer as with the program above could easily have
been done with a pocket calculator. No objections to that and no programming
would have been needed. However, what if you would like to have the position
of the ball for every milli-second of the flight? All that punching on the
calculator would have taken you something like 4 h!
If you know how to program, however, you could modify the code above
slightly, using a minute or two of writing, and easily get all the positions
computed in one go within a second.
An even stronger argument, however, is that mathematical models from
real life are often complicated and comprehensive. The pocket calculator
cannot cope with such problems, even not the programmable ones, because
their computational power and their programming tools are far too weak
compared to what a real computer can offer.
Write programs with a text editor
When Python interprets some code in a file, it is concerned with every
character in the file, exactly as it was typed in. This makes it troublesome to write the code into a file with word processors like, e.g., Microsoft Word, since such a program will insert extra characters, invisible
to us, with information on how to format the text (e.g., the font size and
type).
Such extra information is necessary for the text to be nicely formatted
for the human eye. Python, however, will be much annoyed by the extra
characters in the file inserted by a word processor. Therefore, it is fundamental
that you write your program in a text editor where what you type on the
keyboard is exactly the characters that appear in the file and what Python
will later read. There are many text editors around. Some are stand-alone
programs like Emacs, Vim, Gedit, Notepad++, and TextWrangler. Others
are integrated in graphical development environments for Python, such as
Spyder.
8 See, e.g., https://www.spyder-ide.org/.
