There is very little emphasis these days on teaching programming, in spite of the fact that technology is becoming more and more a dominant aspect of our lives. Perhaps this is because many programmers are self-taught, used to working alone on projects,
and therefore the assumption is that students will learn programming "as they go" or "on their own". This is unfortunate because I think that this aversion to traditional instruction and the preference for "self-taught" programmers leaves some people who want
to learn in the dust.
I have lately become interested in rectifying this problem. A few of my clients have discussed the option of learning programming through tutoring sessions with me. I think that if I had been able to avail myself of such an option when I was first learning
to program, I might have had a much easier time in learning how to properly use computers as the powerful tools that they are.
I believe, however,...
1. Take the sentence: All work and no play makes Jack a dull
boy. Store each word in a separate variable, then print out the
sentence on one line using print.
#! /usr/bin/env python3
# ex1 - words
# All work and no play makes Jack a dull boy.
word1 = "All"
word2 = "work"
word3 = "and"
word4 = "no"
word5 = "play"
word6 = "makes"
word7 = "Jack"
word8 = "a"
word9 = "dull"
word10 = "boy."
print(word1, word2, word3, word4, word5,
word6, word7, word8, word9, word10)
2. Add parenthesis to the expression 6 * 1 - 2 to change its value from 4
#! /usr/bin/env python3
print("6 * 1 - 2 = ", 6 * 1 - 2)
print("6 * (1 - 2) = ", 6 * (1 - 2))
3. Place a comment before a line of code that previously worked, and
record what happens when...
Chapter 2 of How to Think Like a Computer Scientist begins actually exploring Python and its features.
The chapter discusses variables, expressions, and statements. It starts out discussing data types and using the type() function to determine the type of some literals, like strings, integers, and floats. It also discusses using different kind of string
Variables have a name and can be created by using the name you want to give the variable, the assignment token (=), and a value, like so:
lunch = "sandwich"
weight = 150
Variable names have to begin with a letter or underscore (_) and can't be one of Python's reserved keywords (http://openbookproject.net/thinkcs/python/english3e/variables_expressions_statements.html#variable-names-and-keywords).
Statements are instructions that python can perform. Examples given are while, for, import and others.
Expressions are combinations...
In preparation for offering Python as a subject I'm planning on reviewing and refreshing my basic Python programming skills using the online text "How to Think Like a Computer Scientist", located at:
As I progress through the chapters I plan on writing a brief summary and reflection on the topics covered. I also plan on posting my answers to selected problems from the text.
Python is an exciting, powerful, but easily learned programming language, with a large selection of libraries for achieving many common tasks from file i/o, networking, and various mathematical functions, to cross platform gui development, application
scripting and automation, and other useful and advanced tasks.