Search Header Logo
[iGCS] Array

[iGCS] Array

Assessment

Presentation

Computers

9th Grade

Practice Problem

Easy

Created by

Andy tsui

Used 15+ times

FREE Resource

10 Slides • 4 Questions

1

[iGCS] Array

Slide image

2

Objectives

  • What is array and the terminology related

  • Array in pseudocode

  • Array in Python

3

Imagine you need to have a health monitor program

  • Enter name of the user

  • Enter body temperature in day 1

  • Enter body temperature in day 2

4

Open Ended

Write Pseudocode for the application mentioned before!

5

Same application, but 14 days...

  • The data need to be stored (for future use)

  • And maybe longer than 14 days....

  • For loop can help

6

So if we use for loop, it should be something like:

FOR i <- 1 TO 14:

⠀INPUT day-i

NEXT i


Since the day-i is repeating, but can we do that?

7

Array

  • Array is a collection of variable

  • All of them are same data type

  • And similar kind of data

8

Declare array

# Both of the followings will declare an array of n elements


DECLARE temperatures[0..n-1]


DECLARE temperatures[1..n]


Note:

Array size, or number of element, is fixed once it is declared

9

Fill in the Blanks

Type answer...

10

Accessing the array elements

We use [square brackets] to indiciate which element we are accessing:


DECLARE temperatrues[0..13]

temperatures[0] = 37.5


# So the above example, we called "0" is the index of the first element of the array

11

A few key terms:

  • index: the location of an item in an array. In Python index starts from 0

  • size: how many items in the array, array size is fixed

  • element: each item in the array

12

Open Ended

Write the Pseudocode to declare an array of "scores", which consisted of 24 elements.

13

Open Ended

DECLARE scores[0..23]


Write the Pseudocode to assign 100 to first score.

14

Python array Practice

  • Declare an array for 14 temperatures (float) data

  • Write a for-loop to enter those temperatures data, with proper prompt

  • Write another for-loop to calculate the average of those inputted temperature

[iGCS] Array

Slide image

Show answer

Auto Play

Slide 1 / 14

SLIDE