4 ms·
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?
- zedshaw 16y agoTry out my free book: http://learnpythonthehardway.org/ 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 16y agoThanks. 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 16y agoThere is something pretty similar... You might want to lookup on euler problems in python.. http://pyeuler.wikidot.com/ http://pyeuler.wikidot.com/ really cool stuff....
- GrowWebs 16y agonice
- aceregen 16y agoHi 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!
- keefe 16y agoOne 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 http://undefined.org/python/#simplejson maybe? I'm java not python) or whatever. This teaches a key concept : code modularity.
- kilian 16y agoGoogle python class starts with really easy stuff, and it's pretty well written. http://code.google.com/edu/languages/google-python-class/ http://code.google.com/edu/languages/google-python-class/
- JeanPierre 16y agoI 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 http://codingbat.com/python
- anthonyb 16y agoTheir interpreter seems to be broken. eg. for http://codingbat.com/prob/p126968 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)
- anthonyb 16y agoDepending 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/ http://openbookproject.net/py4fun/ also has some simple (ish), but relatively real world problems.
- nfnaaron 16y agoImplement (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 http://en.wikipedia.org/wiki/The_C_Programming_Language The Elements of Programming Style, http://en.wikipedia.org/wiki/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 http://en.wikipedia.org/wiki/Jon_Bentley Programming Pearls, http://netlib.bell-labs.com/cm/cs/pearls/ http://netlib.bell-labs.com/cm/cs/pearls/ The UNIX Programming Environment, http://en.wikipedia.org/wiki/The_UNIX_Programming_Environment http://en.wikipedia.org/wiki/The_UNIX_Programming_Environmen... And, er, Learning Python, http://en.wikipedia.org/wiki/Learning_Python http://en.wikipedia.org/wiki/Learning_Python
- mahmud 16y agoC 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 16y agoNo. 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.
- interesse 16y agoOld, but still good: http://www.pythonchallenge.com/ http://www.pythonchallenge.com/
- Ixiaus 16y agoIf 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.
- imp 16y agoThere'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-introduction/2010/jan/ 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.
- gte910h 16y agohttp://inventwithpython.com/ http://inventwithpython.com/
- ccurland 16y agoThanks 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