top of page

Goblin Hunt >>> Lesson 1: Getting started



Goblin Hunt is a very simple and basic game (we only have 5 brief blogposts to write it). We have a goblin hiding in one of our kitchen cupboards and our aim is to try to find the goblin. Find the goblin and you win; open an empty cupboard and you lose.

You should have already completed Lesson 0, if not please go there first (Numbers start at 0 not 1 in most programming languages). If you've just completed Lesson 0, then you should be at https://repl.it/languages/python3 ready to start writing code.

(1) Type the following two lines of code (do not to copy-paste, typing stuff actually helps understand what you're doing):

print("Welcome to the Goblin Hunt game!!")

print("Can you find the goblin hiding in the kitchen cupboards?")

print() is a type of command called a function. Functions (which are always followed by brackets, or parenthesis () in Python) perform some action. Often they take some input (the stuff that goes in the brackets) and the function does something with that input. In this case the print() function does what it says on the tin: it prints the string of characters that's in the quotation marks "" to the screen.

To run the program so far, click the button that says 'run'. The program's output will appear in the black section on the right. Nothing too exciting so far, I hear you say…

(2) Quotation marks "" tell Python that you want to treat whatever is in them as a string of characters. We call this a string. A string is one type of data (or information) that we will use often in programming.

(3) Let's change these first two lines of code as follows, and include a third line:

print("Welcome to the Goblin Hunt game!!\n")

name = input("What's your name? -> ")

print(name + ", can you find the goblin hiding in the kitchen cupboards?")

Firstly, we have added a \n at the end of the string in the first print() function. This symbol indicates a new line and is simply making the output prettier by adding an empty line. No need to dwell on this too much.

We have then added a new line that has another function: input(). This function does two things: it prints out the string contained within the brackets to screen, but it also waits for the player to type something in. Try it out by running the program ('Run'). The string of characters that the player types in will then be stored in a variable that we chose to call name. A variable is a way of storing some data (information) inside the computer program.

Finally, the second print() command now takes two strings as input, with a + sign in between the two. Note that there are no quotation marks around name since this is not the text we actually want to print, but the variable name that contains the string "Stephen" if I play the game (or whatever name you type in).

You can now move on to Lesson 2 where we'll start preparing the cupboards for the goblin to hide in, and learn about some new types of data along the way.

Any issues, problems or questions? Email me at info@codetoday.co.uk

62 views

Recent Posts

See All

Python Coding for Young People

CT-Unlimited-FinalRAW-transparent.png

Codetoday Unlimited is for the curious teenager or preteen keen to learn proper Python coding. Stephen's courses start from the basics and carry on to intermediate and advanced levels.

Python Coding for Adults

The Python Coding Place is Stephen's platform full of courses and other resources for beginners and intermediate learners. The focus is on clarity and Stephen's unique communication style.

bottom of page