
Ask HN: Simple exercises for a python beginner? - rbarooah
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?
======
zedshaw
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.

~~~
rbarooah
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.

~~~
apurva
There is something pretty similar... You might want to lookup on euler
problems in python.. <http://pyeuler.wikidot.com/> really cool stuff....

------
nfnaaron
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...](http://en.wikipedia.org/wiki/The_Elements_of_Programming_Style)

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...](http://en.wikipedia.org/wiki/The_UNIX_Programming_Environment)

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

~~~
mahmud
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.

~~~
nfnaaron
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.

------
JeanPierre
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>

~~~
anthonyb
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)

------
kilian
Google python class starts with really easy stuff, and it's pretty well
written. <http://code.google.com/edu/languages/google-python-class/>

------
imp
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...](http://curiousreef.com/class/mit-
opencourseware-600-introduction/2010/jan/)

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.

------
anthonyb
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.

------
ccurland
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
cjcurland@cox.net or give Robin a email at robin@sublime.org

------
keefe
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.

------
interesse
Old, but still good:

<http://www.pythonchallenge.com/>

~~~
Ixiaus
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.

------
gte910h
<http://inventwithpython.com/>

