Skip to content

make_something

Make the computer draw a mountain

Start here if you have never written any code at all. This is the whole thing you are about to make, and it appears the moment you press run.

what appears on your screen

A mountain for Ada * *** ***** ******* ********* |

No internet needed. Nothing to install except Python itself. No account, no sign up, nothing that can go wrong on somebody else's computer. Ten lines and it is yours.

Here is the whole thing

All of it, nothing hidden. The spaces at the start of the three indented lines matter in Python, so keep them exactly as they are.

name = "Ada"
size = 5

print("A mountain for", name)
print()

for row in range(1, size + 1):
    spaces = " " * (size - row)
    stars = "*" * (row * 2 - 1)
    print(spaces + stars)

print(" " * (size - 1) + "|")

Put your own name in the top line instead of Ada. That is the first thing to change, because then it is yours rather than ours.

How to run it

  1. Get somewhere to run Python. On a phone, open the browser and search for an online Python compiler. Nothing to install. On a computer, if Python is already there you have an editor called IDLE, otherwise ask an adult before installing anything. Doing this on a phone is a page of its own.
  2. Make a new file and save it as mountain.py. In a browser editor there is nothing to save, the box is already there.
  3. Paste the code in, change Ada to your name, and save it again.
  4. Run it. In a browser editor that is the Run button. In IDLE it is the Run menu, then Run Module. Your mountain appears straight away.

if_it_breaks

If you get red text, nine times out of ten it is the spaces. Python cares about them. The three lines underneath the for line each start with four spaces, and the last line starts with none. Check those before anything else.

Now change one number

Go to the second line and change the 5 to a 12. Change nothing else. Run it again.

A mountain for Ada * *** ***** ******* ********* *********** ************* *************** ***************** ******************* ********************* *********************** |

You did not write more code. You changed one character and the program did the extra work. That is the entire reason people write programs instead of drawing things by hand, and you have just done it on your fourth minute of programming.

Try 30. Try 100 and watch it run off the side of the window.

What the lines actually do

You do not need this to make it work. Read it when you want to know why it worked.

The two at the top

name and size are boxes with things in them. Python calls them variables. You put a value in once at the top, and everywhere underneath, the name stands for whatever is in the box. That is why changing one number changed twelve lines of output.

The for line

for row in range(1, size + 1) means do the next bit once for each row, counting from 1 up to the size. The three indented lines underneath are the bit that gets repeated. The indent is how Python knows where the repeat starts and stops, which is why the spaces matter so much.

The trick with the stars

In Python, multiplying a piece of text repeats it. So "*" times 5 gives you five stars. Each row prints some spaces to push it across, then an odd number of stars, which is what makes the sides slope evenly instead of stepping.

Make it yours

easy

Change the stars

Swap the star for a different character. A hash, a full stop, an emoji. See which one still looks like a mountain.

easy

Give it a longer trunk

The last line draws one trunk. Make it draw three, stacked, so it looks more like a tree.

harder

Turn it upside down

Make it point downwards instead. You only need to change what the row counts from and to.

harder

Ask for the size

Instead of typing the size in, have the program ask whoever runs it. Search for Python input, and remember that what comes back is text, not a number.

next

Send your program out to the internet

Once this one runs, the next step is a program that goes and fetches something real from another website. Make Python fetch you a real dog photo.

All the things you can make

your_progress

Got your mountain to appear? Tick it off.

Kept in this browser only. No account, no sign up, and nothing about you reaches us.