News for hackers. Stuff that matters.

Ask HN: Simple exercises for a python beginner?

I've been helping a complete beginner to learn the basics of python. He's got a basic understanding of loops, conditionals, and input and print statements, plus a few functions, and knows how to use a text editor to write code. He really wants some simple programming exercises he can do to help him consolidate his knowledge. I've given him a few exercises I made up, but we are looking for more. Is there a good resource for this ( not project Euler! ), or do people here have any ideas?
( 18 comments | 26 points | on HN )
Re:Ask HN: Simple exercises for a python beginner? by zedshaw on Sunday May 16, 2010 @04:50PM (#1352755)
Try out my free book:

http://learnpythonthehardway.org/

It's 1/2 done, but the first half is a really good start for someone totally new to programming and the language.

Also, submit tickets if your friend runs into trouble spots so I can clear them up.

Re:Ask HN: Simple exercises for a python beginner? by rbarooah on Sunday May 16, 2010 @05:14PM (#1352807)
Thanks. I've just gone through it. It looks like a great way to cover a lot the basic texture of things that most programming books ignore. I'm recommending it to him. I will be interested to see how you deal with the more complex topics.
Re:Ask HN: Simple exercises for a python beginner? by apurva on Monday May 17, 2010 @12:22AM (#1353554)
There is something pretty similar... You might want to lookup on euler problems in python.. http://pyeuler.wikidot.com/ really cool stuff....
Re:Ask HN: Simple exercises for a python beginner? by aceregen on Sunday June 27, 2010 @08:00AM (#1465379)
Hi Zed,

Just want to give kudos to you for the book. I agree with your approach of teaching the language - the portion on argv, args was clearer than the tutorials I have went through so far.

Keep up the good work!

Re:Ask HN: Simple exercises for a python beginner? by GrowWebs on Tuesday May 18, 2010 @04:02PM (#1358837)
nice
Re:Ask HN: Simple exercises for a python beginner? by nfnaaron on Sunday May 16, 2010 @08:31PM (#1353131)
Implement (without looking) or re-implement (after looking) the examples and exercises from the following or similar books; the book's language doesn't matter:

The C Programming Language, http://en.wikipedia.org/wiki/The_C_Programming_Language

The Elements of Programming Style, http://en.wikipedia.org/wiki/The_Elements_of_Programming_Sty...

Writing Efficient Programs, http://en.wikipedia.org/wiki/Jon_Bentley

Programming Pearls, http://netlib.bell-labs.com/cm/cs/pearls/

The UNIX Programming Environment, http://en.wikipedia.org/wiki/The_UNIX_Programming_Environmen...

And, er, Learning Python, http://en.wikipedia.org/wiki/Learning_Python

Re:Ask HN: Simple exercises for a python beginner? by mahmud on Sunday May 16, 2010 @09:08PM (#1353184)
C and Unix as a prerequisite for Python? I don't think so. Python is much higher level and has richer features.

I think he is better of learning from more pythonic sources, and learning programming in general.

Re:Ask HN: Simple exercises for a python beginner? by nfnaaron on Sunday May 16, 2010 @10:34PM (#1353332)
No. Not to learn C. These books, and others like it (for C and any other language (including Python)) have exercises.

The guy was looking for exercises.

You can implement the exercises in whatever language you're learning. Python, for example.

Re:Ask HN: Simple exercises for a python beginner? by JeanPierre on Sunday May 16, 2010 @07:58PM (#1353089)
I think Codingbat is a good place to begin/start with python, and it's also good for exercises. As they have an online interpreter, you get a definitive yes/no answer, with elaboration where things go wrong. http://codingbat.com/python
Re:Ask HN: Simple exercises for a python beginner? by anthonyb on Sunday May 16, 2010 @09:17PM (#1353205)
Their interpreter seems to be broken. eg. for http://codingbat.com/prob/p126968 the following solution seems ok:

    def centered_average(nums):
        sum(nums[1:-1]) // (len(nums) - 2)
but gives me an error: 'sum is not defined'.

Also, all of their examples use two spaces, not four (the python standard)

Re:Ask HN: Simple exercises for a python beginner? by kilian on Sunday May 16, 2010 @06:12PM (#1352906)
Google python class starts with really easy stuff, and it's pretty well written. http://code.google.com/edu/languages/google-python-class/
Re:Ask HN: Simple exercises for a python beginner? by imp on Monday May 17, 2010 @10:01AM (#1354351)
There's an MIT OpenCourseWare class (6.00) that is an introduction to Python and computer science. If your friend wants to do the problems in that course, there are people working through it together on Curious Reef (disclaimer, it's my website): http://curiousreef.com/class/mit-opencourseware-600-introduc...

You can post your work, view others' work, leave comments, and ask questions. 29 people have done at least the first lesson so far. It's one of the most active classes on the site.

Re:Ask HN: Simple exercises for a python beginner? by anthonyb on Sunday May 16, 2010 @08:12PM (#1353103)
Depending on your friend and how he learns, he might find that solving real problems consolidates his knowledge faster than more exercises. Pick a library that does something that he's interested in, and which gives some immediate feedback, and let him at it. Pygame, pyglet and django spring to mind, or some sort of web scraper or GUI automater (eg. pywinauto) to interface with the real world. http://openbookproject.net/py4fun/ also has some simple (ish), but relatively real world problems.
Re:Ask HN: Simple exercises for a python beginner? by ccurland on Monday May 17, 2010 @08:50PM (#1356062)
Thanks everyone that is posting information. I am the person that my friend Robin is currently helping with. I was fine up to the for - statement and on.I will be graduating from High School next year and am going for my degree in the computer programming field. Any recommendations please email me at [email protected] or give Robin a email at [email protected]
Re:Ask HN: Simple exercises for a python beginner? by keefe on Sunday May 16, 2010 @06:03PM (#1352891)
One of our primary tasks as engineers is integrating other libraries. I'd suggest picking a task like mysql integration, reading json (http://undefined.org/python/#simplejson maybe? I'm java not python) or whatever. This teaches a key concept : code modularity.
Re:Ask HN: Simple exercises for a python beginner? by interesse on Monday May 17, 2010 @06:46AM (#1353994)
Re:Ask HN: Simple exercises for a python beginner? by Ixiaus on Monday May 17, 2010 @11:32AM (#1354557)
If I could up vote this comment again, I would. The Python Challenge helped me tremendously by providing enough bite sized "projects" to learn the innards and idioms of the language.
Re:Ask HN: Simple exercises for a python beginner? by gte910h on Monday May 17, 2010 @01:18PM (#1354864)