Complete the following diagram for the letters IPO.
Input
Process
Output
Understand why we learn to program
Understand how to develop and run a small program in Python
Understand and implement basic input and output methods in Python
I am able to open Python IDLE and open and save code in it
I am able to read and implement some Python code
A computer program is a collection of instructions that performs a specific task when executed by a computer. A computer requires programs to function. A computer program is usually written by a computer programmer in a programming language.
$files = directory_list_files("/folder/images/")
for each ($files as $file)
$img = new Image
$img->open($file)
$img->transform_resize(600, 400)
$img->save($file)
end for
Instruction
$files = directory_list_files("/folder/images/")
for each ($files as $file)
$img = new Image
$img->open($file)
$img->transform_resize(600, 400)
$img->save($file)
end for
Statement
$files = directory_list_files("/folder/images/")
for each ($files as $file)
$img = new Image
$img->open($file)
$img->transform_resize(600, 400)
$img->save($file)
end for
print("Hello World")
That’s all there is to this program!
😮
print
is a function in Python. print
is used to send something to the
display.
Z:\
)
Our next program will take in a persons name and display it. For this example we will use the
input()
function.
print("Please insert your name")
print("Hello there")
print(input())
We can also combine pieces of text when we display them using commas in the print
function which makes the output much nicer:
print("Please insert your name")
print("Hello there", input())
This is called concatenation.
Python has a bunch of interesting things you can do in the print function:
For example, this will stop Python taking a new line after outputting to the screen:print('Hello world!', end=' ')
The \n
character is the standardised method of adding a new line within a piece of text.
print('Hello\nworld")
You may have come across the wait block in Scratch.
Most programming languages offer identical functionality.
In Python we use the time.sleep
function after importing the time library (more
later):
import time
time.sleep(1)
print('Hello everyone!')
What is z?
a = 15
b = 3
c = 4
z = a + b × c ÷ 2
What was your answer?
Steps:
c [4] ÷ 2 = 2
b [3] × 2 = 6
12 + a [15] = 21
print("Please insert your name)
print["Please insert your name"]
print("Please insert your name)
print["Please insert your name"]
print("Please insert your name')
print["Please insert your name"]
print("Please insert your name')
print(input)
print(input)
print("Please insert your name')
#Ask the user for their name and display it
print("What is your name?")
print(input())
# Program to calculate product of two numbers
# J Balfour
# March 2021
Grade yourself on the lesson's success criteria at balf.vote/jTuYpisQV6hg
Apply a filter: