NOTE: This web page was last modified on Tue May 31 06:00:27 2016 UTC.

Grading is done and has been entered into reg.buu.ac.th.

2016/05/08@10:00 ICT   matplotlib output images added.
2016/05/09@15:15 ICT   New rule prohibiting even watches and announcing eye glasses inspection for final exam added.
2016/05/13@13:51 ICT   Improve demo007b.py, add demo007c.py file.
2016/05/14@14:31 ICT   Add demo007d.py file.
2016/05/14@14:50 ICT   Add demo005b.py file.
2016/05/14@19:56 ICT   Add demo005c.py and demo005d.py files.
2016/05/27@18:05 ICT   Add exam3 and its solutions.
2016/05/30@15:04 ICT   Actually, five people skipped exam #3.... 2016/05/30@15:41 ICT   Add final exam.
2016/05/30@15:54 ICT   Add final exam answers.
2016/05/31@13:00 ICT   Add note that grades have been submitted.




Mr. Ham's Python 3.5 demos for BUU

The files you want are below. Since SourceForge changed ownership recently, you might want to download everything in case this site goes away.

Always check the 'Last modified' date to see if you really have the latest version or not. When I make fixes, I re-upload them and the 'Last modified' date will automatically be updated to show that the file has been changed.

If you don't have it already, you might want the officially allowed Python 3 Cheat Sheet, but remember it must be one sheet of paper, prineted on two sides, in color. Black and white, or two page versions will not be permitted. You didn't have to buy any textbook - surely you can go to a decent print shop that has a color laserjet printer and print one piece of paper with two sides?

All files are text files and use UNIX®-style line endings. If you want 0x0D 0x0A line endings for your Microsoft® operating system then you need to do the conversion yourself.[1]

You might want to look at some sample midterm exams from other teacher's courses while you study for yours.

Exam 1 files

There were two slightly different exams since the test was spread over two different days. You should be able to recognize the one you took. The solutions are not unique, since many lines in the source code were duplicated. The robot grader uses your answers to unscramble the original file, and then your unscrambled version is compared with the original file to determinte your score. Any time you left a slot blank, that is an incorrect answer.

Tech demo files from 2016/01/14

NOTE: You may have to force your browser to use UTF-8 encoding to see the non-English strings display correctly.

Tech demo files from week of 2016/01/25

The inventory application from week of 2016/01/25

Files from the lectures of 2016/02/01

Files from the lecture of 2016/02/04

Files from the lecture of 2016/02/05

Since I did the procedural to OOP conversion live in both lectures, the results are slightly different. Wise students will examine both the 2016/02/04 and 2016/02/05 solutions.

Files from the start of lecture of 2016/02/08

Files from the end of lecture of 2016/02/08

Files from the lecture of 2016/02/11

File from 2016/02/12

Files from 2016/02/15

Attack of the psuedo-psycho zombie GUI mutants.....

Well, OK, not quite, but here is a GUI demo for you to study. I have not tested it on Mac or Windows yet - have you?

Files from 2016/02/18 & 2016/02/19

File from 2016/03/14

Files from 2016/03/21

Files from 2016/03/22

Files from 2016/03/25

The bug was subtle. Since the menu choices for both Save and Save As both called the savefile() function with no parameter to distingish which choice was used, the function logic failed. It would say "If I know the file name, 'Save As' is just 'Save' the the file name I already know." That is not what we wanted. I used lambda in the menu definitions (the command= part) so that I could send a boolean parameter to let the function know if we were doing Save or Save As and now it seems to work as intended. I was already doing something like that with the openfile() function, but hadn't realized I needed it for the savefile() function too. The bug was a logic bug, not a tkinter bug and not a python syntax bug. I'm sorry the bug fix took so long. The changes were small, but it took me a while to figure out exactly what it was doing. It was not possible for me to change what was being done until I knew exactly what the problem was, but once I could reliably produce the bug it was fairly simple to implement the fix. I also used the assert statement which you may not have seen before. See the official assert documentation for details on how it works.

Files from 2016/03/28

Files from 2016/03/29

Files from 2016/03/31

Files from 2016/04/01

Well, I think I got it working. But it needs more testing. Are you up to the challenge?

Files from 2016/04/04

Files from 2016/04/2[89]

These programs use the matplotlib package. Like all things with python3, matplotlib works well but the documentation doesn't have enough examples. I will provide examples of the things you need to know, and I expect you to:

  1. write the examples down in your paper notebook
  2. run & study the example until you think you understand them
  3. play with the examples by making small changes and verify your understanding
The point of this course was specifically to help you get started with using python3 with matplotlib so you can use that in your future projects for BUU (and later on the job or when you study for a master's degree). This semester had too many holidays, and the final exams are in only a few weeks, so don't be lazy - get serious and please learn this stuff now!

Normally you would use matplotlib to generate a graph in some format required by your word processing software, and then include that plot in your document. Here I show how to generate an on-screen plot which is useful while you debug your data and/or plot, then three different output formats (PDF, PNG, and SVG) each of which has it's strengths and weaknesses. If you need some other format (PS, JPG, etc.) you would need to tweak the examples a bit, or use image converter software with the output of one of these examples.

There are basically two general types of plots: plots from a set of data points you have, or plots from an equation that generates data points. In a real experiement, you probably have your actual results data as a set of data points, and your theoretical or expected output as an equation, so you need to learn both types of plots. Fortunately matplotlib has excellent support for both types of plots, so learning how to do things like setup your axes, label the graph or points on it, etc. is the same for both types of plots.

Files from 2016/05/01

These files were created for the special make-up class.

These files were created `live' during the lecture.

Files from 2016/05/02

These examples are for simple curve fitting. They all use hard-coded data points, but you could merge in the csv code from demo001.py or even adapt to use sqlite with code from the sqlite3_demo.py program. These are our first examples that use the numpy module.

Files from 2016/05/13

Files from 2016/05/14

Midterm Exam

The midterm exam was held on March 10, 2016, and covered python3 text mode programming.

Exam 3

Exam 3 was held on April 4, 2016, and covered python3 and tkinter, but not matplotlib or numpy. I could not post this or the answers before the final exam because five people failed to take exam 3 before the final exam. You can ask Dilok, Atthawud, Pasuta, Nattanicha, and Saranyu about that.

Final Exam

The final exam was held on May 19, 2016, and covered matplotlib and a tiny bit of numpy for curve fitting.

Miscellaneous Resources

You might want to support language switching in your application, or currency conversion. In that case, some images of national flags might be helpful.

Hey, vi is not your enemy...

Many people had horrible problems with even exiting vim. When you are ready to exit, press the 'esc' key twice (it's in the upper left-hand corner of all normal keyboards). This will ensure you exit insert mode. What you do next depends on which vi you are using.

See basic vi commands if you need help with vi.

But if you still hate vi....

One tool I have used with python on both Windows® and Linux® is Geany which is a very lightweight IDE that works very well with Python. It has syntax highlighting that most people here like, it does not require modes like vi, and it has menus, can display Thai, etc. I used it when I taught a seminar and most students liked it. If you really don't like vi, try geany. Other features that it has include code folding, auto-completion, plugins, and more. It is free and GPL.


1. Stack overflow solutions to do the conversion. VIM can work with the files without conversion, and so can python, but if you use some other editor you probably need to do the conversion.