Practice Python

follow us in feedly Atom feed XML

Weekly beginner Python exercises

27 December 2014

Draw A Game Board

Exercise 24 (and Solution)

This exercise is Part 1 of 4 of the Tic Tac Toe exercise series. The other exercises are: Part 2, Part 3, and Part 4.

Time for some fake graphics! Let’s say we want to draw game boards that look like this:

 --- --- --- 
|   |   |   | 
 --- --- ---  
|   |   |   | 
 --- --- ---  
|   |   |   | 
 --- --- --- 

This one is 3x3 (like in tic tac toe). Obviously, they come in many other sizes (8x8 for chess, 19x19 for Go, and many more).

Ask the user what size game board they want to draw, and draw it for them to the screen using Python’s print statement.

Remember that in Python 3, printing to the screen is accomplished by

  print("Thing to show on screen")

Hint: this requires some use of functions, as were discussed previously on this blog and elsewhere on the Internet, like this TutorialsPoint link.

The main topic of this exercise is functions. They are tricky, and deserve lots of practice and thought. Here are a few links in case you want some more reading.

  1. Functions on TutorialsPoint
  2. Hands-on Python, by Loyola University
  3. Learn Python the Hard Way
  4. ZetCode

There are hundreds more out there - read and practice away!

Happy Coding!

Happy coding!

Forgot how to submit exercises?

comments powered by Disqus