We are using a lot of tutorials to help us prepare our Python materials. I'll post some here in case others are interested. Below is a simple starter one for matplotlib, the Python plotting library.
PythonProgramming.net
Monday, April 3, 2017
Anaconda
Recently installed the Anaconda Python IDE. I was pleasantly surprised to find that it does, indeed, install many of the libraries such as pandas for data manipulation, numpy for arrays and matplotlib for plotting. These are available from the regular command line as well iPython and Jupyter.The install went smoothly and only took a few minutes on my Windows 10 computer. The distribution was about 420 MB. This is what it installed. More about these in later posts.
Sunday, April 2, 2017
Loops in Java and Python
Below are the basic looping statements in Java and Python. Java has three: while, do...while and for, Python has two: while and for. But not do...while, although there are ways to accomplish the same thing. Also Python has an interesting approach to the for statement, sometimes called a for each. It iterates over a sequence selecting each element in turn. In the example below if counter is 15 it will iterate over i from 1 through 15.
for i in range(1,counter+1):
sum = sum + i;
On another note I decided I would I put the code for the Python scripts in a function and then called the function. This is more similar to Java which requires the existence of a class with a main() method. See the example below. It basically checks to see if the script being run is the main program, not an import.
def Loops():
counter = 10
i = 1
while i <= counter:
print("i = {}".format(i))
i = i + 1
if __name__ == "__main__":
Loops()
Click on the image below to see the code for the various loops.
for i in range(1,counter+1):
sum = sum + i;
On another note I decided I would I put the code for the Python scripts in a function and then called the function. This is more similar to Java which requires the existence of a class with a main() method. See the example below. It basically checks to see if the script being run is the main program, not an import.
def Loops():
counter = 10
i = 1
while i <= counter:
print("i = {}".format(i))
i = i + 1
if __name__ == "__main__":
Loops()
Click on the image below to see the code for the various loops.
Saturday, April 1, 2017
Switch statement in Java and equivalent in Python
Here is another Java/Python comparison. This one for the switch statement in Java. I used elif in Python to keep it simple for beginners. Click on the image to see an expanded version on box.com.
Java and Python if statements comparison
Here is a comparison of Java and Python for the if statement. We are preparing our Python scripts to parallel (at least as much as possible) the Java class from Logical Operations. So we may as well publish them for our reference as well as anyone else who might be interested. It also includes the pseudocode. See screenshots on box.com.
jGrasp and Python
In the course of working on our new Python class we discovered you can run Python as well as Java from jGrasp. While I am not recommending this one way or another it did have a nice side effect. You can develop and test Java programs in parallel with their Python versions right in the same session. By the time we are done developing our new Python training material we should have a lot of side-by-side comparisons of the code for the same tasks. So far it has been running about 1/2 the code in Python vs. Java. While that is a substantial reduction it is not as dramatic as I thought it would be. I may do another parallel stream in pseudocode, mostly for use in college classes.
Thursday, March 30, 2017
New Python Course
I have been looking into Python lately, mostly with an interest in Data Science and Data Analytics. Python is a lot of fun and very powerful with access to a huge library. It has a very clean syntax which may be one of the reasons it has been gaining favor for beginning courses in computer science. So far I have not found any commercial courseware like the type available from Logical Operations and other vendors. So we are going to develop our own course! It will be based on our Introduction to Programming with Java course. We will loosely follow that topic outline using examples and practice files from Python. We will probably just use IDLE but could go with PyCharm or Anaconda or an equivalent IDE. Maybe down the road we can get into some of the neater stuff like numpy amd matplotlib, too.
Subscribe to:
Posts (Atom)



