Introduction:

In this project you will learn how to write a Python program telling people all about you.

Step 1: Saying hello

Let’s start by writing some text.

Activity Checklist

  • Open the blank Python template Trinket: jumpto.cc/python-new.

  • Type the following into the window that appears:

    screenshot
    screenshot

    The line #!/bin/python3 just tells Trinket that we’re using Python 3 (the latest version).

  • Press ‘run’, and you should see that the print() command prints everything between the quote marks ''.

    screenshot
    screenshot
  • If you make a mistake, you’ll get an error message instead - telling you what went wrong!

    Try it! Delete the end quote ' or the closing bracket ) (or both) and see what happens.

    screenshot
    screenshot
  • Replace the quote or bracket and click ‘run’ to make sure your project works again.

Save Your Project

You don’t need a Trinket account to save your projects!

If you don’t have a Trinket account, click the down arrow and then click ‘Link’. This will give you a link that you can save and come back to later. You’ll need to do this every time you make changes, as the link will change!

screenshot
screenshot

If you have a Trinket account, you can click ‘remix’ to save your own copy of the Trinket.

screenshot
screenshot

Challenge: What’s on your mind?

Change the code above, to print something more interesting about you!

screenshot
screenshot

Save Your Project

Step 2: ASCII art

Let’s print something much more fun than text… ASCII art! ASCII art (pronounced ‘ask-e’) is creating pictures out of text.

Activity Checklist

  • Let’s add some art to your program - a picture of a dog!

    screenshot
    screenshot
  • If you click ‘run’, you’ll see that there’s a bug in your new code.

    screenshot
    screenshot

    That’s because your text contains a quote, which Python thinks means the end of the text!

    screenshot
    screenshot
  • To fix this, just put a backslash \ before the quote in the word here's. This tells Python that the quote is part of the text.

    screenshot
    screenshot
  • If you prefer, you can use 3 quotes ''' instead of 1, which allows you to print multiple lines of text with 1 print statement:

    screenshot
    screenshot

Save Your Project

Challenge: About yourself

Write a Python program to tell others about yourself, by using text and ASCII art. You can create images of your hobbies, friends… or anything you like!

Remember that the code you write in Trinket is public. Don’t share any personal information like your full name or address!

Here’s an example:

screenshot
screenshot

Save Your Project

Step 3: The Year 2025

You can also do calculations and print numbers. Let’s find out how old you’ll be in the year 2025.

Activity Checklist

  • To calculate how old you’ll be in the year 2025, you need to subtract the year you were born from 2025.

    Add this code to your program:

    screenshot
    screenshot

    Notice that you don’t need to put quotes around numbers.

    (You’ll need to change the number 2006 if you were born in a different year.)

  • Click ‘run’ and your program should print your age in the year 2025.

    screenshot
    screenshot
  • You could improve your program by using input() to ask the user their age and store it in a variable called born.

    screenshot
    screenshot
  • Run your program and then enter the year you were born. Did you get another error messgae?

    That’s because anything typed into your program is text, and it needs to be converted to a number.

    You can use int() to convert the text to an integer (‘integer’ means ‘whole number’).

    screenshot
    screenshot
  • You can also create another variable to store your calculation, and print that instead.

    screenshot
    screenshot
  • Finally, you can make your program easier to understand by adding a helpful message.

    screenshot
    screenshot

Save Your Project

Challenge: Your age in dog years

Write a program to ask the user their age, and then tell them their age in dog years! You can calculate a person’s age in dog years by multiplying their age by 7.

screenshot
screenshot

In programming, the symbol for multiplication is *, and is usually shift+8 on the keyboard.

Save Your Project

Challenge: Calculating text

Did you know that you can also calculate text?!

What does the following program print to the screen? See if you can guess correctly before running the program.

screenshot
screenshot

Can you make up any words of your own? You could even make your own patterns!

screenshot
screenshot

Save Your Project