0% found this document useful (0 votes)
1 views16 pages

01 Inputs%2C Variables and Outputs - Procedural Python

Uploaded by

x79rd8dpyk
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views16 pages

01 Inputs%2C Variables and Outputs - Procedural Python

Uploaded by

x79rd8dpyk
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 16

Procedural Python:

Inputs, Variables and


Outputs
Computer Science UK www.computerscienceuk.com
Lesson Objectives
Lesson Objectives
• Understand how to program outputs in python,
• Understand how to program inputs in python,
• Understand the need to store inputs in python,
• Understand how to store inputs into variables in python,
Lesson Outcomes
• Carrying out a number of programming tasks.
Literacy – Key Words

Input Values which get sent from the user into the computer
Variable The place where inputs get stored by the program
Output The values which get sent from the computer to the user

Computer Science UK www.computerscienceuk.com


Hands up if you can tell me the following…

“The Python Code needed


to display some words on
the screen”

Computer Science UK www.computerscienceuk.com


…in Python we use print()

Output

The print() statement will output the contents of its brackets.

If we wish it to print some text, the text must be surrounded by quotes!

Computer Science UK www.computerscienceuk.com


Lets Practice
• On your whiteboard…

Write the code to display your name on the


screen

Did you…
1) Write the word print (with a lowercase p?)
2) Write brackets after the word print?
3) Write your name inside the brackets?
4) Write your name within quotes (inside the brackets)?

Computer Science UK www.computerscienceuk.com


Lets Practice
• On your whiteboard…

Write the code to display a message of your


choice on the screen

Did you…
1) Write the word print (with a lowercase p?)
2) Write brackets after the word print?
3) Write your message inside the brackets?
4) Write your message within quotes (inside the brackets)?

Computer Science UK www.computerscienceuk.com


Quick Class Task

1. Visit coder.computerscienceuk.com/coder/

2. Write the first program ever made…get your program to display


the text HELLO WORLD, when the program is run

3. If you get this working, make it display a message of your choice

TIPS:
• You will need to use the print() statement
• To run the program, click the rocket icon!

Computer Science UK www.computerscienceuk.com


Can you tell me the following…

1. The python code needed to display a word on


the screen

2. The python code needed to ask the user for an


input

3. The way python can store user inputs

…let’s look at inputs and storage then!!


Computer Science UK www.computerscienceuk.com
Programming Inputs & Storing Inputs

In python to request user inputs, we


use the input statement:

input
()
input(“what is your
name?”)

But we also need to store what the user types in, otherwise the input will be
lost!

Computer Science UK www.computerscienceuk.com


How does a computer store inputs?

• In programming, inputs and data are stored in something


called a variable.
• It can simply be thought of as a storage box.
• Technically though, it is a reference to a memory location
where the data is to be stored.
• The variable must be given a name, and it can hold a single
data item

Variable called ‘ANSWER’ Contents is anything we type


in

Computer Science UK www.computerscienceuk.com


Storing Inputs in PYTHON

input(“what is your
name?”)
As we saw before, the problem with the above is that whatever the user types in, it
doesn’t actually go anywhere
We need to STORE IT…

answer = input(“what is your


name?”)
What the user types in (e.g. their name)
ANSWER

Now, whatever’s typed in, is stored in a variable called answer.

Computer Science UK www.computerscienceuk.com


Programming Inputs & Storing Inputs in PYTHON

In Python, the ‘input’ statement would


allow our program to ask the user to
enter an input.

The ‘answer’ variable would store the


input.
Output

And we could use the answer variable with a ‘print’


statement to output the inputted value.

Computer Science UK www.computerscienceuk.com


Programming Inputs & Storing
Inputs

Summary

• ‘answer’ is the variable (memory location) where the user’s input will be stored

• input(“What is your name?”) displays the “what is your name?” message onto the screen and waits for
the users input.

• Once the user has typed in their name the input is stored in the variable labelled “answer”

• print(answer) then simply displays the contents of variable “answer” onto the screen

Computer Science UK www.computerscienceuk.com


Can you tell me the following
now?
1. The python code needed
to display a word on the
screen?

2. The python code needed


to ask the user for an
input?

3. The way python can store


user inputs?

Computer Science UK www.computerscienceuk.com


An important difference between a print and an input
statement

PRINT Just
displays a
message!
INPUT Displays
a message and
waits for a user
input!
So, it needs to be assigned
to a variable if we want to
store what the user types
in…

Computer Science UK www.computerscienceuk.com


Lesson Activity

• Read the information in the lesson’s workbook

• Complete the PRIMM tasks provided.

Computer Science UK www.computerscienceuk.com

You might also like