c8 Editable Lower Quality
c8 Editable Lower Quality
PROGRAMMIN
G
Chapter Outline
8.2.1 One-dimensional
8.1.1 Variables and Constants
Arrays
8.1.2 Basic Data Types 8.2.2 Two-dimensional
8.1.3 Input and Output Arrays
8.1.4 Programming Fundamentals
8.1.5 Nested Statements
8.1.6 Procedures, Functions and
8.3.1 Reading from a
Parameters
file
8.1.7 Library Routines
8.3.2 Writing to a file
8.1.8 Creating a Maintainable Program
Chapter Outline
8.2.1 One-dimensional
8.1.1 Variables and Constants
Arrays
8.1.2 Basic Data Types 8.2.2 Two-dimensional
8.1.3 Input and Output Arrays
8.1.4 Programming Fundamentals
8.1.5 Nested Statements
8.1.6 Procedures, Functions and
8.3.1 Reading from a
Parameters
file
8.1.7 Library Routines
8.3.2 Writing to a file
8.1.8 Creating a Maintainable Program
Variables and
Constants
Definition:
Both variables and constants are containers for storing a
value. Once created, the variable is stored in a computer
memory and it can be used.
10
refer to the data
Variable is created
stored in the
Computer memory memory by name
Variables VS
Constants
.py
total_price_var = 0
ticket_price_const = 25
Constant
Variables number_of_tickets = input("Enter
number of ticket")
total_price_var = number_of_tickets
* ticket_price_const
*Python does not
require any
separate
declarations and
does not
differentiate
between
constants and
variables
Chapter Outline
8.2.1 One-dimensional
8.1.1 Variables and Constants
Arrays
8.1.2 Basic Data Types 8.2.2 Two-dimensional
8.1.3 Input and Output Arrays
8.1.4 Programming Fundamentals
8.1.5 Nested Statements
8.1.6 Procedures, Functions and
8.3.1 Reading from a
Parameters
file
8.1.7 Library Routines
8.3.2 Writing to a file
8.1.8 Creating a Maintainable Program
Basic Data
Types
In order for a computer system to process and store data effectively, different kinds of data
are formally given different TYPES, so that:
"a" in ascii
Data can be stored in
an appropriate way 110000
1 97 in denary
In order for a computer system to process and store data effectively, different kinds of data
are formally given different TYPES, so that:
In order for a computer system to process and store data effectively, different kinds of data
are formally given different TYPES, so that:
Auto validation
5 Basic Data
Types
Intege Real/ Char String Boolea
A positive or AFloat
positive or A variable or A variable or A variable or
r
negative whole
number that can
negative number
with a fractional
constant that is
a single
n
constant that is
several
constant that
can have only
be used with part. Real numbers character characters in two values
mathematical can length. Strings TRUE or FALSE.
operators be used with vary in length
mathematical and may even
operators have no
characters
(known as an
empty string)
Exampl
es
Intege Real/ Char Strin Boolea
Float
r g n
25 25.0 'c' "ccc" TRUE
"" FALSE
Test your
understanding!
8.2.1 One-dimensional
8.1.1 Variables and Constants
Arrays
8.1.2 Basic Data Types 8.2.2 Two-dimensional
8.1.3 Input and Output Arrays
8.1.4 Programming Fundamentals
8.1.5 Nested Statements
8.1.6 Procedures, Functions and
8.3.1 Reading from a
Parameters
file
8.1.7 Library Routines
8.3.2 Writing to a file
8.1.8 Creating a Maintainable Program
Input and
Output
Main function
Output
Input
Inpu
t Pseudocode
Python Code
INPUT Age
IF Age > 18
THEN
OUTPUT "You are an
adult"
ELSE
OUTPUT "You are a kid"
ENDIF
Inpu Each input needs to
be accompanied by a
t
PROMPT prompt
PROMPT
Pseudocode
Python Code
OUTPUT "What is your age"
INPUT Age
IF Age > 18
THEN
OUTPUT "You are an
adult"
ELSE
OUTPUT "You are a kid"
ENDIF
Input and
Output
Input can also be in the form of file (excel, image). See Chapter 8.3
Output
Input
Inpu
t
All inputs default as strings, so if the input should be an integer or real number, commands
are also used to change the data type of the input (for instance, in Python these are int() or
float()).
Outpu
For a program to be useful, the user needs to know what results
are being output, so each output needs to be accompanied by a
message explaining the result.
t Pseudocode
Python Code
INPUT Age
IF Age > 18
THEN
OUTPUT "You are an
adult"
ELSE
OUTPUT "You are a kid"
ENDIF
Output
PROGRAMMING TIME
TASK
SPECIFICATION
So far we have learned the following topics:
• Variables and Constant
• Basic Data Type
• Input and Output
Let's put everything that we have learned into practice.
TASK 1
VOLUME OF A SPHERE
To calculate the volume of a sphere, we can use the
formula:
TIPS:
You need to create a constant called PI that has the
value of 3.142. You can perform multiplication in
python using the * symbol. A fraction can be created
using the division / symbol (eg. 4/3).
TASK 2
VOLUME OF A CYLINDER
To calculate the volume of a cylinder, we can use the
formula:
TIPS:
You need to create a constant called PI that has the
value of 3.142. You can perform multiplication in
python using the * symbol.
ANSWER (TASK 1)
ANSWER (TASK 2)
Chapter Outline
8.2.1 One-dimensional
8.1.1 Variables and Constants
Arrays
8.1.2 Basic Data Types 8.2.2 Two-dimensional
8.1.3 Input and Output Arrays
8.1.4 Programming Fundamentals
8.1.5 Nested Statements
8.1.6 Procedures, Functions and
8.3.1 Reading from a
Parameters
file
8.1.7 Library Routines
8.3.2 Writing to a file
8.1.8 Creating a Maintainable Program
Sub Chapter Outline
8.1.4.1 Sequencing
8.1.4.2 Selection
String handling
8.1.4.5
8.1.4.2 Selection
String handling
8.1.4.5
Show football
Yes
Do you like videos
football?
Show other
No
videos
Selection
Pseudocode
Python Code
INPUT Age
IF Age > 18
THEN
OUTPUT "You are an If
statement
adult"
ELSE
OUTPUT "You are a kid"
ENDIF
Selection
or a CASE statement.
Java Code
Pseudocode
INPUT Grade
CASE OF Grade
A : OUTPUT "Excellent"
B : OUTPUT "Not bad huh"
C : OUTPUT "Fair"
D : OUTPUT "Work harder"
OTHERWISE : OUTPUT "Invalid input"
ENDCASE
Selection
INPUT Grade
CASE OF Grade
A : OUTPUT "Excellent"
B : OUTPUT "Not bad huh"
C : OUTPUT "Fair"
D : OUTPUT "Work harder"
OTHERWISE : OUTPUT "Invalid input"
ENDCASE
PROGRAMMING TIME -
SELECTION
TASK 1 - ODD OR EVEN
Ask the user for a number. Determine if the number
entered is an odd number or an even number. Print out
the result.
Tips:
When we divide a number by 2, an odd number will
have a remainder of 1 and an even number will have a
remainder of 0.
Tips:
A simple if-else statement is not enough!
ANSWER (TASK 1)
ANSWER (TASK 2)
Sub Chapter Outline
8.1.4.1 Sequencing
8.1.4.2 Selection
String handling
8.1.4.5
Iteration takes place in algorithm when the rules determine that a step
or steps should be repeated until a condition is met or until told to
stop.
Another word for iteration is loop. There are 3 different types of loop in
iterative programming.
Another word for iteration is loop. There are 3 different types of loop in
iterative programming.
Steps incremented to
the counter variable
at each iteration
Notes: You don't have
for keyword to specify step if the
value is 1.
OUTPUT
OUTPUT
step = 2
Count-controlled
loop
Another word for iteration is loop. There are 3 different types of loop in
iterative programming.
This is where a condition must be true before the loop or operation takes place.
This type of loop is known as a while loop.
Total ← 0
OUTPUT "Enter value for mark, -1 to finish "
INPUT Mark
WHILE Mark <> -1 DO
Total ← Total + Mark
OUTPUT "Enter value for mark, -1 to finish"
INPUT Mark
ENDWHILE
Pre-condition This is where a condition must be true before the loop or operation
loop (Pseudocode) takes place.
SYNTAX
Condition that must be
met before the BREAKDOW
indented codes can be
run N
Total ← 0
OUTPUT "Enter value for mark, -1 to finish "
INPUT Mark
WHILE Mark <> -1 DO
The above program will keep adding what the user enters until user keys in
the value "-1". The total will be printed.
Iteration
Another word for iteration is loop. There are 3 different types of loop in
iterative programming.
This is where a condition must be true after the loop or operation takes place. It
can be implemented using the REPEAT ... UNTIL loop in Pseudocode.
Total ← 0
Mark ← 0
REPEAT
Total ← Total + Mark
OUTPUT "Enter value for mark, -1 to
finish "
INPUT Mark
UNTIL Mark = -1
Post-condition This is where a condition must be true after the loop or
loop (Pseudocode) operation takes place.
SYNTAX
BREAKDOW
N
Total ← 0
Mark ← 0
REPEAT
Total ← Total + Mark Indented code. It will
OUTPUT "Enter value for mark, -1 to run at least once.
finish "
INPUT Mark Condition that must be
UNTIL Mark = -1 met for the indented
codes to repeat
This is where a condition must be true after the loop or
Post-condition
operation takes place.
loop (Java Code)
SYNTAX
*DO ... WHILE loop in Java
BREAKDOW
N
*Python only
supports pre-
condition and
Condition that must be met for count-controlled
the indented codes to repeat loop
PROGRAMMING
TIME
ITERATION
TASK 1 - MULTIPLES OF 3
Use a FOR loop (count-controlled) to output the first 5 multiples of 3. Your program should
output the following:
TASK 2-
COUNTDOWN
Use a FOR loop (count-controlled) to output a countdown from 10 to 0. Your program should
output as the diagram below:
TASK 3-
COUNTDOWN (WHILE
LOOP)
Use a WHILE loop (count-controlled) to output a countdown from 10 to 0. Your program
should output as the diagram below:
TASK 4-
I WANT POSITIVE NUMBER
Write a program that asks user to input numbers REPEATEDLY until the user keys in a
positive number.
Eg. If the user enters the value "5", your program should output the value 15 (5 + 4 + 3 + 2
+ 1 + 0 = 15).
Test case:
INPUT = 3, OUTPUT = 6
INPUT = 10, OUTPUT = 55
INPUT = 100, OUTPUT = 5050
ANSWER - TASK 1
ANSWER - TASK 2
ANSWER - TASK 3
ANSWER - TASK 4
ANSWER - TASK 5
Sub Chapter Outline
8.1.4.1 Sequencing
8.1.4.2 Selection
String handling
8.1.4.5
8.1.4.2 Selection
String handling
8.1.4.5
upper
length
substring
Find the number of characters in a
"abcdefghijk" string.
0 1 2 3 4 5 6 7 8 9 10
substring
a b c d e f g h I j k
*In Python, index starts at 0.
(one character)
Extracting part of a string
"abcdefghijk"
0 1 2 3 4 5 6 7 8 9 10
substring
a b c d e f g h I j k
*In Python, index starts at 0.
(range of *syntax variable[x:y], x is the starting position and
y is the ending
characters)
Extracting part of a string
"abcdefghijk"
1 2 3 4 5 6 7 8 9 10 1
substring
a b c d e f g h I j k1
*In Pseudocode, index starts at 1.
(range of
characters) text <- "abcdefghijk"
shorten_text <- SUBSTRING(text, 1,
3)
upper
OUTPUT upper_text
# "ABCDEFGHIJK"
# "ABCDEFGHIJK"
Convert all the letters in a string to
"abcdefghijk" lowercase
lower
# "abcdefghijk"
Sub Chapter Outline
8.1.4.1 Sequencing
8.1.4.2 Selection
String handling
8.1.4.5
Add + +
Subtract - -
Multiply * *
Divide / /
Raise to the power
of ^ **
Remainder
division MOD %
Integer
division DIV //
Arithmetic
Operators
Equal = ==
Greater than
or equal to >= >=
Less than or
equal to
<= <=
OR Either True OR or
OPERATORS
TASK 1 - USING
OPERATORS
Takes 2 numbers as inputs from the user (N1 and N2):
• Output with a suitable message if all three numbers are not equal
• Output with a suitable message if all numbers are equal.
ANSWER - TASK 1
ANSWER - TASK 1B
Sub Chapter Outline
8.1.4.1 Sequencing
8.1.4.2 Selection
String handling
8.1.4.5
8.2.1 One-dimensional
8.1.1 Variables and Constants
Arrays
8.1.2 Basic Data Types 8.2.2 Two-dimensional
8.1.3 Input and Output Arrays
8.1.4 Programming Fundamentals
8.1.5 Nested Statements
8.1.6 Procedures, Functions and
8.3.1 Reading from a
Parameters
file
8.1.7 Library Routines
8.3.2 Writing to a file
8.1.8 Creating a Maintainable Program
Sometimes, it is necessary to execute one IF
Nested statement, followed by another, and then
Selection followed by another. This is when nested
selection is needed.
Nested IF-statement
Normal IF-statement
Nested SYNTAX
Selection BREAKDOW
N
Nested IF-statement
An IF
statement
An IF within an
IF
statement statement
Nested SYNTAX
Selection BREAKDOW
N
What does the code below do?
Output
>>
Nested STEP-BY-
Iteration STEP
Code
for counter in range(1,3):
print("Counter = " + str(counter))
for another_counter in range(1,3):
print("Another counter = " + str(another_counter))
Output
>> Counter = 1
Nested STEP-BY-
Iteration STEP
Code
for counter in range(1,3):
print("Counter = " + str(counter))
for another_counter in range(1,3):
print("Another counter = " + str(another_counter))
Output
>> Counter = 1
Nested STEP-BY-
Iteration STEP
Code
for counter in range(1,3):
print("Counter = " + str(counter))
for another_counter in range(1,3):
print("Another counter = " + str(another_counter))
Output
>> Counter = 1
>> Another counter = 1
Nested STEP-BY-
Iteration STEP
Code
for counter in range(1,3):
print("Counter = " + str(counter))
for another_counter in range(1,3):
print("Another counter = " + str(another_counter))
Output
>> Counter = 1
>> Another counter = 1
>> Another counter = 2
Nested STEP-BY-
Iteration STEP
Code
for counter in range(1,3):
print("Counter = " + str(counter))
for another_counter in range(1,3):
print("Another counter = " + str(another_counter))
Output
>> Counter =1
>> Another counter = 1
>> Another counter = 2
>> Counter =2
Nested STEP-BY-
Iteration STEP
Code
for counter in range(1,3):
print("Counter = " + str(counter))
for another_counter in range(1,3):
print("Another counter = " + str(another_counter))
Output
>> Counter =1
>> Another counter = 1
>> Another counter = 2
>> Counter =2
Nested STEP-BY-
Iteration STEP
Code
for counter in range(1,3):
print("Counter = " + str(counter))
for another_counter in range(1,3):
print("Another counter = " + str(another_counter))
Output
>> Counter =1
>> Another counter = 1
>> Another counter = 2
>> Counter =2
>> Another counter = 1
Nested STEP-BY-
Iteration STEP
Code
for counter in range(1,3):
print("Counter = " + str(counter))
for another_counter in range(1,3):
print("Another counter = " + str(another_counter))
Output
>> Counter =1
>> Another counter = 1
>> Another counter = 2
>> Counter =2
>> Another counter = 1
Nested STEP-BY-
Iteration STEP
Code
for counter in range(1,3):
print("Counter = " + str(counter))
for another_counter in range(1,3):
print("Another counter = " + str(another_counter))
Output
>> Counter =1
>> Another counter =1
>> Another counter =2
>> Counter =2
>> Another counter =1
>> Another counter =2
Nested STEP-BY-
Iteration STEP
Code
for counter in range(1,3):
print("Counter = " + str(counter))
for another_counter in range(1,3):
print("Another counter = " + str(another_counter))
NESTED
STATEMENTS
TASK 1 - MULTIPLICATION
TABLE
Write a nested for loop program to print multiplication table in Python. Your
program should produce the following output.
(Tips: Not an easy problem).
TASK 2 - STARS
Use a nested loop to print the following pattern in Python.
8.2.1 One-dimensional
8.1.1 Variables and Constants
Arrays
8.1.2 Basic Data Types 8.2.2 Two-dimensional
8.1.3 Input and Output Arrays
8.1.4 Programming Fundamentals
8.1.5 Nested Statements
8.1.6 Procedures, Functions and
8.3.1 Reading from a
Parameters
file
8.1.7 Library Routines
8.3.2 Writing to a file
8.1.8 Creating a Maintainable Program
Subroutine
When writing an algorithm, there are often similar tasks to perform that make use of the
same groups of statements. Instead of repeating these statements and writing new
code every time they are required, many programming languages make use of
subroutines, also known as named procedures or functions.
These are defined once and can be called many times within a program.
Subroutine
- Add 5
- Multiply by 3
- Divide by 2
- Add 100
- Minus 20
- Then, print the total.
- Add 5
- Multiply by 3
- Divide by 2
- Add 100
- Minus 20
- Then, print the total.
SIMILAR!
We can group this
chunk of code
together and make a
procedure/function
We can group this
chunk of code
together and make a
procedure/function
And use the function
like
this
SYNTAX
BREAKDOWN function name, parameter, the value which we
def keyword used to call the function insert into the function
Procedure vs Function
cannot be
used here
PROGRAMMING
TIME
FUNCTIONS
TASK 1 - STARS
Write a function that can print one line of stars (*********).
In your codes, call the function 5 times to print 5 lines of stars. Your
program should output the following:
TASK 1B - STARS
EXTENDED
Create a function that takes in a "number" parameter. Using the number(N)
parameter, print N lines of stars. For instance:
user input = 6
user input = 3
TASK 2 - FAHRENHEIT TO
CELCIUS
The formula to convert Fahrenheit to Celsius is
Your function will need to take in a value as parameter and return the
result.
Then, use the function to calculate two input values from the user.
ANSWER - TASK 1
ANSWER - TASK 1B
ANSWER - TASK 2
Chapter Outline
8.2.1 One-dimensional
8.1.1 Variables and Constants
Arrays
8.1.2 Basic Data Types 8.2.2 Two-dimensional
8.1.3 Input and Output Arrays
8.1.4 Programming Fundamentals
8.1.5 Nested Statements
8.1.6 Procedures, Functions and
8.3.1 Reading from a
Parameters
file
8.1.7 Library Routines
8.3.2 Writing to a file
8.1.8 Creating a Maintainable Program
Library Routine
MOD(10,3)
Try it
out in
Value = 10%3
Python
8.2.1 One-dimensional
8.1.1 Variables and Constants
Arrays
8.1.2 Basic Data Types 8.2.2 Two-dimensional
8.1.3 Input and Output Arrays
8.1.4 Programming Fundamentals
8.1.5 Nested Statements
8.1.6 Procedures, Functions and
8.3.1 Reading from a
Parameters
file
8.1.7 Library Routines
8.3.2 Writing to a file
8.1.8 Creating a Maintainable Program
Maintainable
Program
Instead of:
Do this:
Maintainable 3 ways to write a maintainable
Program program
Instead of:
Do this:
Maintainable 3 ways to write a maintainable
Program program
Instead of:
Do this:
Maintainable Fun fact: A book has been
Program written to"teach" programmers
how to write maintainable code.
464 pages!!!
Chapter Outline
8.2.1 One-dimensional
8.1.1 Variables and Constants
Arrays
8.1.2 Basic Data Types 8.2.2 Two-dimensional
8.1.3 Input and Output Arrays
8.1.4 Programming Fundamentals
8.1.5 Nested Statements
8.1.6 Procedures, Functions and
8.3.1 Reading from a
Parameters
file
8.1.7 Library Routines
8.3.2 Writing to a file
8.1.8 Creating a Maintainable Program
One-dimensional
array RECA
P
Variables are memory locations that can store a
piece of data.
10
refer to the data
Variable is created
stored in the
Computer memory memory by name
One-dimensional
array ARRA
Y
An array is a series of these memory locations,
where all of the data is of the same data type.
2 3 4
refer to the
Variable is created
GROUP OF data
Computer memory
stored in the
memory by name
One-dimensional
array ARRA
Y
Each location can still store 1 data, but locations
can be grouped together.
2 3 4
refer to the
Variable is created
GROUP OF data
Computer memory
stored in the
memory by name
One-dimensional
array ARRA
Y
Index
0 1 2
Data
2 3 4
Most programming languages automatically set
the first index of an array to ZERO.
One-dimensional
array ARRA
Index
0 1 2
Y
Data
2 3 4
To retrieve an element of an array, we would just
do:
ARRAYNAME[index]
One-dimensional
array ARRA
Declare an array in Pseudocode
Y
DECLARE MyList:ARRAY[0:2] OF 0 1 2
INTEGER
One-dimensional
array ARRA
Y
Each position in the array can be populated in an array by defining the value
at each index position
MyList[2] = 20
0 1 2
One-dimensional
array ARRA
Y
In Python, arrays are created using the LIST functionality.
0 1 2
Chapter Outline
8.2.1 One-dimensional
8.1.1 Variables and Constants
Arrays
8.1.2 Basic Data Types 8.2.2 Two-dimensional
8.1.3 Input and Output Arrays
8.1.4 Programming Fundamentals
8.1.5 Nested Statements
8.1.6 Procedures, Functions and
8.3.1 Reading from a
Parameters
file
8.1.7 Library Routines
8.3.2 Writing to a file
8.1.8 Creating a Maintainable Program
Two-dimensional A two-dimensional array has multiple columns
array and multiple rows of data, all with the same data
type.Very much like an excel file.
Inde 0 1 2
x
0 2 3 4
1 5 6 7
2 8 9 10
Two-dimensional Example usage:
array A world map in a simple 2D game.
Inde 0 1 2
x G - ground
0 T T G T - tree
Z -zombies
1 Z G G H - humans
2 H G G
Two-dimensional Example usage:
array Students mark in different subjects
Inde 0 1 2
x
StudentA 0 76 65 67
StudentB 1 32 90 75
StudentC 2 66 77 31
Two-dimensional
array PSEUDOCOD
E
Inde 0 1
DECLARE MyList:ARRAY[0:2,0:1] OF x
INTEGER 0
1
TYPE 2
RO COLUMN
Two-dimensional
array PSEUDOCOD
E
Inde 0 1
MYLIST[2,1] <- 10 x
0
2 10
Two-dimensional
array PSEUDOCOD
E
Inde 0 1
OUTPUT MYLIST[0,0] x
0 30
#30 will be OUTPUT
1
2 10
Two-dimensional
array PYTHON
Inde 0 1
x
0 30 20
1 15 5
A two-dimensional array in 2 0 10
Python is basically a list
inside a list!
Two-dimensional
array PYTHON
In Python, you can loop through a list like this.
Two-dimensional STEP-BY-
array STEP
Loop through a list of list in python
Code
big_list = [["a", "b"], ["c", "d"]]
>>
Two-dimensional STEP-BY-
array STEP
Loop through a list of list in python
Code
big_list = [["a", "b"], ["c", "d"]]
>>
Two-dimensional STEP-BY-
array STEP
Loop through a list of list in python
Code
big_list = [["a", "b"], ["c", "d"]]
>>
Two-dimensional STEP-BY-
array STEP
Loop through a list of list in python
Code
big_list = [["a", "b"], ["c", "d"]]
>> a
>>
Two-dimensional STEP-BY-
array STEP
Loop through a list of list in python
Code
big_list = [["a", "b"], ["c", "d"]]
>> a
>>
Two-dimensional STEP-BY-
array STEP
Loop through a list of list in python
Code
big_list = [["a", "b"], ["c", "d"]]
>> a
>> b
Two-dimensional STEP-BY-
array STEP
Loop through a list of list in python
Code
big_list = [["a", "b"], ["c", "d"]]
>> a
>> b
Two-dimensional STEP-BY-
array STEP
Loop through a list of list in python
Code
big_list = [["a", "b"], ["c", "d"]]
>> a
>> b
Two-dimensional STEP-BY-
array STEP
Loop through a list of list in python
Code
big_list = [["a", "b"], ["c", "d"]]
>> a
>> b
>> c
Two-dimensional STEP-BY-
array STEP
Loop through a list of list in python
Code
big_list = [["a", "b"], ["c", "d"]]
>> a
>> b
>> c
Two-dimensional STEP-BY-
array STEP
Loop through a list of list in python
Code
big_list = [["a", "b"], ["c", "d"]]
>> a
>> b
>> c
>> d
PROGRAMMING
TIME
ARRAYS
TASK 1 - SQUARE
Turn every item in the following list into squares. You can print out your
result.
TASK 2 - EXAM MARKS
Create a list of list in python to represent the
data. Then, find out:
• Find out the top marks for Physics, Physics Chemistry Biology
8.2.1 One-dimensional
8.1.1 Variables and Constants
Arrays
8.1.2 Basic Data Types 8.2.2 Two-dimensional
8.1.3 Input and Output Arrays
8.1.4 Programming Fundamentals
8.1.5 Nested Statements
8.1.6 Procedures, Functions and
8.3.1 Reading from a
Parameters
file
8.1.7 Library Routines
8.3.2 Writing to a file
8.1.8 Creating a Maintainable Program
Reading and We have seen programming involves the
writing input of a lot of data.
Pseudocode
Python Code
INPUT Age
IF Age > 18
THEN
OUTPUT "You are an
adult"
ELSE
OUTPUT "You are a kid"
ENDIF
Reading and
writing
Output:
Chapter Outline
8.2.1 One-dimensional
8.1.1 Variables and Constants
Arrays
8.1.2 Basic Data Types 8.2.2 Two-dimensional
8.1.3 Input and Output Arrays
8.1.4 Programming Fundamentals
8.1.5 Nested Statements
8.1.6 Procedures, Functions and
8.3.1 Reading from a
Parameters
file
8.1.7 Library Routines
8.3.2 Writing to a file
8.1.8 Creating a Maintainable Program
Writing to a file
Write
mode
Output
Code