Python

Programming

Lesson 2 - Input & Output

Task 1 - Outputting a Word

In the programming trinket to the left, type the following code:

word = input("Please enter a word ")

print("You entered the word " + word)

Click the play icon to run the code and see what it does.


What the code does

word = input(“Please enter a word”)

This displays the text inside the input command on screen and stores whatever you entered in the variable named word

print(“You entered the word ” + word)

This prints on screen the text in speech marks followed by what is in the variable word. A comma is used to join the two pieces of information together.

Task 2 - Favourite Film

Create a program where the user enters their name and enters their favourite film. You should create your program in the trinket below.

Use the success criteria below to help you:

  • Use input to ask the user to “Enter their name” and store it in a variable that has a suitable name

  • Use input to ask the user to “Enter your favourite film” and store it in a variable that has a suitable name

  • Use print to create an output that looks something like this when run:

Extension

Improve your program so that the information is split over two lines. You must still only use one print command, an example of this is shown below:

How to create a new line in a print command

To create a new line in a print command you must use \n, an example of how this works is shown below:

Extension - Birthday Program

You need to create a program where the person enters their name and enters the day of their birthday this year as well the month, use the success criteria below and the skills from the first task to do this. You should create the program in the trinket below:

Use the success criteria below to help you:

  • Use input to ask the user to “Enter your name” and store it in a variable called name

  • Use input to ask the user to “Enter the day of your birthday this year” and store it in a variable called day

  • Use input to ask the user to “Enter the month of your birthday” and store it in a variable called month

  • Use print to display:

“Hello” name “, your birthday month is” month “ and the day of your birthday this year is” day

An example of what the program could look like when run is shown to the right.

Extension

Improve your print command so that after it says Hello and their name it starts a new line; an example is shown below:

Evidence point

Open the Assignment in Google Classroom called Student Evidence - L2 - Input Output.

Take a screenshot of your code for:

  • Task 1 - Outputting a Word

  • Task 2 - Favourite Film

  • Extension - Birthday Program

For each program click on Share and choose Link. Copy the link and paste it into the document, this means you can come back to it in future lessons.