Archive for March, 2016

Square around the screen again

March 31, 2016

Dan and I have come up with a total of 5 methods of programming this little problem.  There are undoubtedly a plethora of good solutions.  I gave this to my programming class to do in Small Basic.  SB is perfect for this kind of little assignment, it does simple graphics without any fuss.  I have three kids in the class.  Two solutions were very similar to the state variable solution, especially since I showed one kid what a state variable did and how it worked and he shared the idea to the other two kids.  I expected the same basic solution from all three kids.  Kid number three had to be different.  He turned in the code and I stared.  “What the heck did he do?!”  It took me a while to figure out he had come up with a recursive solution.  Very clean, very unique.  I love it.

If you are going to teach programming the cookie cutter has to go out the window.  In math there is usually a “best” method to reach the solution.  In programming there are good solutions and bad solutions, all of which will work.  And sometimes there are solutions that are just better than anything you may have thought of.  Smart kids in math are manageable, you know where they are going and what tools they have to work with to get there.  Smart kids in programming find tools you did not know existed and they will use them in ways you never thought of.  I love it.

The continuing sage of moving a square around the screen using a state variable with Python

March 23, 2016

This is fun just finding different ways to do the same simple problem.  After getting pygame working (3 hours?  Again, I am not bright, just stubborn. ) the code was 60 minutes.  I had to look up how to use pygame and found some good examples.  (blit?  Who came up with blit?)  I had to chase down the usual weird things in the code but no big deal.  Being the stone-cold idiot I am I figured if I can get this working with pygame.py I should learn how to do it with graphics.py.  It took me a while (really stubborn) to figure out to copy the graphics class to a text file, rename it .py then drop it into the Lib>site-packages folder in the Python folder.  Nowhere does any clever soul give that little detail.  The directions just say “put this where Python can see it.”  Not good.  Anyway once I got the messy setup details figured out the code with the graphics.py was 30 minutes.  Again I found a nice example.  It still has a minor drawing issue and gets slower with each lap.  Tonight’s entertainment.  I cancelled cable TV so this is my replacement.  (I have to get cable TV back, this stuff is going to make me go blind.)  Dan Schellenberg, where I got the square idea in the first place, picked up on the “let’s do it in Python” idea and has three variations.  The third one listed here is one of his.

Now I stare at these and think “how anal do I really want to get with this?”  I look at the code in those 4 if statements.  They are all the same except for the parameters.  I think I could make that a procedure and pass parameters …  Hummmm.

I really need to do more of these.  All my Python is learned on the job.  For that matter all my coding is learned on the job (except for the 2 FORTRAN courses in ‘71 and ‘80, and one intro Java course in ‘90).  This leads to a rather sketchy foundation and almost no breadth.  I can do what is in the book I am using and only to the chapters I have had time to learn.  Projects like this have no chapter and have no solution determined by the chapter you are reading at the time.

I now have 5 good solutions to this one problem.  Two mine and 3 Dan’s.  Anybody have any more that are simple or have refinement suggestions I could learn from?

 

With pygame.py.

  1. def main():
  2.     import pygame
  3.     pygame.init()
  4.     width = 500
  5.     height = 500
  6.     white = (255,255,255)
  7.     state = 0
  8.     right = 0
  9.     down = 0
  10.     left = width
  11.     up = height
  12.     step = .5
  13.     main_surface = pygame.display.set_mode((width, height))
  14.     redSquare = pygame.image.load(“redSquare.png”)
  15.     while True:
  16.         ev = pygame.event.poll() # Look for any event
  17.         if ev.type == pygame.QUIT: # Window close button clicked?
  18.             break # … leave game loop
  19.         main_surface.fill(white)
  20.         if state == 0:
  21.             right = right + step
  22.             main_surface.blit(redSquare, (right,0))
  23.             if right >= width – 20:
  24.                 right = 0
  25.                 state = 1
  26.         elif state == 1:
  27.             down = down + step
  28.             main_surface.blit(redSquare, (width – 20, down))
  29.             if down >= height – 20:
  30.                 down = 0
  31.                 state = 2
  32.         elif state == 2:
  33.             left = left – step
  34.             main_surface.blit(redSquare, (left – 20, height – 20))
  35.             if left <= 20:
  36.                 left = width
  37.                 state = 3
  38.         elif state == 3:
  39.             up = up – step
  40.             main_surface.blit(redSquare, (0, up – 20))
  41.             if up <= 20:
  42.                 up = height
  43.                 state = 0
  44.         pygame.display.flip()
  45.     pygame.quit() # Once we leave the loop, close the window.
  46. main()

With graphics.py.

  1. from graphics import *
  2. win = GraphWin(‘Screen’, 500,500)
  3. def main():
  4.     width = 500
  5.     height = 500
  6.     state = 0
  7.     right = 0
  8.     down = 0
  9.     left = width
  10.     up = height
  11.     step = .5
  12.     while True:
  13.         if state == 0:
  14.             right = right + step
  15.             rect = Rectangle(Point(right,0),Point(right+20,20))
  16.             rect.setFill(“red”)
  17.             rect.draw(win)
  18.             if right >= width – 20:
  19.                 right = 0
  20.                 state = 1
  21.         elif state == 1:
  22.             down = down + step
  23.             rect = Rectangle(Point(width – 20,down),Point(width,down + 20))
  24.             rect.setFill(“red”)
  25.             rect.draw(win)
  26.             if down >= height – 20:
  27.                 down = 0
  28.                 state = 2
  29.         elif state == 2:
  30.             left = left – step
  31.             rect = Rectangle(Point(left – 20,height – 20),Point(left,width))
  32.             rect.setFill(“red”)
  33.             rect.draw(win)
  34.             if left <= 20:
  35.                 left = width
  36.                 state = 3
  37.         elif state == 3:
  38.             up = up – step
  39.             rect = Rectangle(Point(0, up – 20),Point(20,up))
  40.             rect.setFill(“red”)
  41.             rect.draw(win)
  42.             if up <= 20:
  43.                 up = height
  44.                 state = 0
  45. main()

With just the native turtle.  (Thanks to Dan Schellenberg.)

  1. import turtle
  2. theWindow = turtle.Screen()          #theWindow.setup(width=400, height=400)
  3. bob = turtle.Turtle()
  4. bob.shape(“square”)
  5. bob.penup()
  6. bob.speed(0)
  7. #determine edges
  8. edgeBuffer = 20
  9. rightEdge = theWindow.window_width()/2 – edgeBuffer
  10. leftEdge = theWindow.window_width()/-2 + edgeBuffer – 10  #the 10 is due to the way that python turtles
  11. topEdge = theWindow.window_height()/2 – edgeBuffer + 10   #draw the square shape…
  12. bottomEdge = theWindow.window_height()/-2 + edgeBuffer
  13. #move to starting location and set original state
  14. bob.setpos(leftEdge,topEdge)
  15. bob.setheading(0)                          #facing east
  16. speed = 5
  17. state = 0
  18. while True:
  19.   if state == 0:
  20.     bob.setx( bob.xcor() + speed )
  21.     if bob.xcor() >= rightEdge:
  22.       state = 1
  23.   elif state == 1:
  24.     bob.sety( bob.ycor() – speed )
  25.     if bob.ycor() <= bottomEdge:
  26.       state = 2
  27.   elif state == 2:
  28.     bob.setx( bob.xcor() – speed )
  29.     if bob.xcor() <= leftEdge:
  30.       state = 3
  31.   elif state == 3:
  32.     bob.sety( bob.ycor() + speed )
  33.     if bob.ycor() >= topEdge:
  34.       state = 0
  35. theWindow.mainloop()

Small Basic and more fun with Python

March 22, 2016

I am always looking for simple programming ideas to give to the kids that make them think and are doable in a couple of class periods.  This little square around the screen is in the general idea.  I figured I would have the kids do it in Small Basic, teach the state variable idea then have them do the same thing in Python.  We had done the traffic signal program earlier this year so the concept is a refresher.  It took me 30 minutes to get it working in SB.  The trouble is I am teaching a Python class.  Python does not have built-in shapes or sprites that animate easily.  You have to use pygame.py or graphics.py.  Both are version sensitive.  Neither is plug and play.  Neither is a nice simple install that the kids could figure out on their own.  The install directions are written by an expert for experts.  So I decide to use pygame to do this exercise.  I am using Python 3.4.  Need the right pygame.  Pygame for 3.4 in not in the usual pygame site.  Search the web.  Find the right pygame.  Delete old version of pygame before installing new version.  (Took a while to figure this little detail out.)  Three hours later I sort of have the program working.

After I get it working in Python I kind of sat back and looked at the process I went through for the last few hours.  Not the coding, that just require picking through the book to get the syntax and working slowly through the programming logic, but at the process required just to get the Python resources ready to go.  I think I can say I could not tell a kid to get this little program working in Python without giving them a whole lot of setup help.

The Small Basic package just makes life so much simple for the classroom teacher.  No install issues, simple IDE, simple documentation, no fuss, no muss.  For a classroom teacher being able to not have to worry about setup, versions (2.7 or 3.5?), multiple IDE choices (Eclipse, PyScripter, etc), and extra packages (pygame, graphics, …) that need to be loaded to do graphics, sprites and so on, is just a huge life saver.  No dinking with the registry and no putting path names in the environmental variables (both things that the average classroom programming teacher would not have access to anyway).

Picking the right language to teach intro programming can be a big decision for a teacher and a curriculum.  You really cannot lose with Small Basic.  Yes, SB is missing some fancy features; parameters, class building and local variables are the big ones I can think of, but those are sort of nice to be missing.  When you reach a point where those are really needed it is time to step up to Java or Python.  I sometimes think the perfect programming language for teaching would have a switch to turn these added features on.  But then the teacher might be tempted not to teach other languages.  Now that would be a big mistake.

Office 365 could be a Google killer

March 17, 2016

Last Saturday I went to a Microsoft Innovative Educator seminar.  Six hours of Microsoft Office 365 show-and-tell.  Good stuff.  Office Mix, OneNote, Office 365, Window 10, Sway, and some other miscellaneous odds and ends.  Way too much stuff way to fast but enough to give an idea of what Office 365 is all about.  The seminar could easily be a two day event.  I went to the event just to see if Office 365 is something my teachers could use.  We are a Google school and although the price is right Google is missing some major feature Office 365 has.  I was hoping to get enough understanding to be able to pass on what I learned to the staff that would be willing to use this stuff.  The seminar was too brief for that.  Even after such a fast show-and-tell I could see huge possibilities for the techie teachers.  Those that feel comfortable using tech tools.  OneNote, Office Mix and Class Notebook could be big for some teachers.  I really appreciate Microsoft for putting on these free seminars but they can be a bit frustrating.  They are teasers.  They show just enough to see the incredible possibilities but do not give enough time to actual learn or practice with the tools.  Missoula County Public Schools (not me, I am the private school) hosts a Google Fest every year.  “Best practices for using Google Apps” kind of thing.  It is not free but there is still a big turnout.  Microsoft needs to jump on this band wagon.  At the moment there are just not enough people in Montana familiar with Office 365 to hold a self-driven event.  Earlier this year I attended a two day seminar on Creative Coding with Games and Apps.  Enough time was spent actually working on TouchDevelop to get a good idea on how to use it.  Office 365 needs something like that.  With some promotion and training Office 365 could bury Google Apps.

After the seminar I hurried back to school with the intent of at least getting Office 365 set up for the school.  I wanted the students and staff to be able to use the free Office 2016 download.  I managed to get my domain verified with Microsoft.  Not a big deal other than getting a magic number to the company that manages my domain name.  After the verification I dug through the Office 365 site and could not locate the download.  I contacted MS tech support (submit the request and 2 minutes later I get a phone call) and after some looking and trying the tech suggests I call sales.  I sent a help request to sales and 5 minutes later I get a call.  I have to have some kind of not free volume purchasing agreement with Microsoft to have access to the Office 2016 download.  Crash and burn.  Some day the administration really has to cough up some money for something like this.  I will be retired before that happens.

Although I am disappointed I could not get the Office 2016 for the kids I have learned quite a bit in the last few days.  The first is Microsoft has really fast, and I mean really fast, tech support response.  The second is that Office 365 has some really cool tools for education.  And third (and I should know this from experience) there is no such thing as a free lunch.

 

Should we teach math in high school?

March 11, 2016

Should we teach math in high school?  I say no.  Now before you get up in arms with a “math is the foundation of the Universe” argument here is what I mean.  We should not be teaching math, we should be teaching how to learn math.  Look at the average high school math text book, be it Geometry, Algebra I or Pre-Calc.  There is a lot of stuff in there.  Of all that stuff we math teachers teach in a year how much is retained by the average student?  I am talking the average student here, not the kid that is taking 3 honors courses, is applying for MIT and CalTech scholarships and asks those questions in class where all you can say is “give me a day or two to figure this out”.  As a guess (with 33 years of experience behind it) 90% of what we teach in math class goes in one ear and out the other.  Don’t believe me?  Give your usual end of chapter test to a regular class (not the honors kids, most of them are math geeks to some extent and are usually a school minority) on some messy topic.  Trig is always a good one or graphing non-linear functions without a calculator.  Now a month later surprise the kids by giving a test on the same material.  Without even actually doing this you can predict the results.  The scores will be lower.  Of course the level of retention will vary depending on the kid and the teacher but overall we can assume a significant loss of knowledge.  So why are we throwing all this math stuff at these kids when most of it will be gone in a fairly short time?  Personally I think it is tradition.  It is the way we math teachers have done it forever and that is the way we are going to continue to do it forever.  I do not think the results are justifying the means.

Now where did this thought stream come from?  Larry Cuban posted this article from the NYTimes.  Now I admit I read newspaper articles with a grain of salt, most of the time they are just hype and BS but this one sort of hit a chord.  Right now I am teaching a Math II course, primarily geometry and a dash of algebra, to normal every day sophomores.  These kids are not into math.  They do not like math.  Math is boring, confusing, stupid, useless, weird, not connected to the real world, and involves thinking (a skill not high on their list of fun things to do).  Looking at what I have them doing most of the time I have to agree 100%.  So I have been head scratching on how to fix this course without throwing the baby out with the bath water.

Now many years ago when I was in high school (Had to walk up hill in 3 feet of snow to get to school.  Same thing to get home.) when I wanted the square root of 532 to some accuracy better than my slide rule would give I grabbed a CRC book and looked it up in the table or, if a CRC was not handy, I looked in some book for the ugly algorithm to compute square roots.  (For those readers educated in the calculator era this may make no sense to you.  Find someone with gray hair to explain.)  I did not memorize the square root of 532, I looked it up.  In the intervening years looking something up has changed.  Google was invented.  Access to the internet is expected.  It seems to me that the teaching of math has sort of ignored these lovely inventions.  I am trying to correct this oversight in my Math II class, hopefully without losing the baby.

(There is nothing really new here but I live in Montana.  We are a little slow.  One school I taught at had a regular announcement that the kids riding their horses to school were responsible for getting their horse manure at the hitching rail in front of the school to the manure pile in the back of the school.  No shit.  (Slight pun there.))

All the kids have a smart phone and I am expecting them to use it.  The traditional math class consists of “here is a formula (or technique) and here are a bunch of practice problems.  I am trying to reverse that.  Here is a problem, find a formula (or technique) to solve it.  This is not as easy as it seems for me.  For many years I have followed the usual math teaching trend of putting something fancy on the board, explaining it, working some sample problems and then dishing out the homework so the kids can get the concept sort of in their heads.  With the usual results of having to do the whole thing over again the next year for the same kids in the next level class.  An example of my new approach is “Find the surface area and volume of the 5 Platonic solids with edge length 6.”  No preamble, no board work, just a sheet of paper with the question.  “What the heck is a Platonic solid?” they ask.  I reply “You tell me.”  The phones come out, the heads get together, and someone says “I found it”.  I wander around the room.  I do not want them to memorize this formula, I want them to be able to find the formula.  I do not want to teach them the math, I want them to find the math then I will help them figure it out.

Most of the math taught in high school is not something for day to day usage.  It is specialty math.  Even something as common as right triangle trigonometry is a specialty math.  Those that use it regularly (not sure who they are, maybe the building fields, and math teachers of course) memorize it, the rest of the world just needs to know how to look it up and use it once they have found it.

There is one minor problem with this approach.  No phones on the SAT, the ACT, standardized tests, and so on and on.  That is where throwing out the baby comes in.  Maybe if I can just get these kids to not fear math and convince them it is not the child of Satan by using this “look it up” approach maybe they will collect the fundamental skills that makes math doable.

I have a General Mathematics textbook published in 1939.  The chapters look identical to a modern high school/college pre-calc textbook.  The old book is thinner and the chapters are more condensed but it teaches the same topics I teach in pre-calc the exact same way my modern textbook does.  Just no pretty pictures or politically correct “extra” at the end of each chapter.  There is something wrong here.  77 years with no fundamental changes in material or technique.  Try that in Computer Science.