0% found this document useful (0 votes)
48 views

Displaying A Message in Python

This document provides steps for writing a basic Python program that prints greetings to the user. [1] The program is built up through a series of tasks that have the student first print a simple string, then print a greeting with a variable, add additional print statements, and finally take user input. [2] The student is prompted to predict output, write code, run their program, check for errors and modify the code between each task. [3] The goal is to create a program that greets the user by name after asking for their input.

Uploaded by

chabiba1981
Copyright
© © All Rights Reserved
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views

Displaying A Message in Python

This document provides steps for writing a basic Python program that prints greetings to the user. [1] The program is built up through a series of tasks that have the student first print a simple string, then print a greeting with a variable, add additional print statements, and finally take user input. [2] The student is prompted to predict output, write code, run their program, check for errors and modify the code between each task. [3] The goal is to create a program that greets the user by name after asking for their input.

Uploaded by

chabiba1981
Copyright
© © All Rights Reserved
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 4

Year 8 – I am an Advanced Python Programmer Worksheet

Lesson 1 – First steps

First steps
Task 1 . Output
Step 1

Type the Python program below in your development environment.

print("Hello world!")

Step 2
Run your program.
If you encounter an error message, read it and try to fix the problem.
Use the list below to check for common errors If your error isn’t included in the list, write down
(and tick ✓ if you find yours). how you fixed it.

misspelt print
(this includes using capitals) I didn’t
missed one or both of print’s brackets
encounter any
used square brackets instead of round
brackets
errors.
missed one or both quotation marks
around "Hello world!"

Step 3
What was the output of the program, once you managed to run it successfully?

Hello world!

Step 4
Modify the program so that it displays a different greeting to the user.

Task 2 . Assignment
Step 1
Type the Python program below in your development environment

Page 1
Year 8 – I am an
Advanced Python
Programmer

(alternatively, you can modify the existing program from the previous task).

1 user = "Claude"
2 print("Hello", user)

Step 2
What do you expect the output of the program to be when you run it?
(Answer this question before you run the program.)

(“Hello”, “Claude”)

Step 3
Run your program.
If you encounter an error message, read it and try to fix the problem.
Use the list below to check for common errors If your error isn’t included in the list, write
(and tick ✓ if you find yours). down how you fixed it.

missed one or both quotation marks


around "Claude" I didn’t
missed one or both of print’s brackets encounter any
missed one or both quotation marks
around "Hello"
errors.
missed the comma between "Hello" and
user

Step 4
What was the output of the program, once you managed to run it successfully?

('Hello', 'Claude')

Step 5
Modify the assignment on line 1, so that the program displays a different name when greeting the
user. Make it display your name!

Page 2
Year 8 – I am an
Advanced Python
Programmer

Task 3 .
Step 1
Extend the existing program from the previous task by typing in two similar additional statements.
Note that line 4 is incomplete.

1 user = "Claude"
2 print("Hello", user)
3 lucky = 13
4 print(“My lucky number is”, lucky )

Step 2
Complete line 4, so that the output of the program is:

Hello Claude
My lucky number is 13

Make sure that your program displays the value of the lucky variable, not just the number 13.

Step 3
Run your program.
If you encounter an error message, read it and try to fix the problem.
Write down any errors that you encountered and how you fixed them.

I didn’t encounter any error messages.

Page 3
Year 8 – I am an
Advanced Python
Programmer

Task 4 . Input
Step 1
Modify the first line of the existing program from the previous task.

1 print("What’s your name?")


2 user = input()
3 print("Hello", user)

Step 2
Run your program.
If you encounter an error message, read it and try to fix the problem.
Write down any errors that you encountered and how you fixed them.

I didn’t encounter any error messages.

Step 3
Once you manage to run the program, you should see this prompt:

What’s your name?

The program is still running: it is executing the input function, which is waiting for the user to type
something on the keyboard.
Type your name and press Enter. What is the output of the program?

('Hello', 'Ramisa')

Step 4
Run your program again.
Type a different name and press Enter. What is the output of the program?

('Hello', 'Bloom')

Page 4

You might also like