Preliminary Software Engineering
Unit 1 - Programming Fundamentals
Unit 1 - Programming Fundamentals
  • 1 - Programming Fundamentals
    • Programming Fundamentals Content
  • 2 - Python
    • Expected Python Knowledge
    • GitHub
    • Learning Python
    • Data Structures and File Management
      • Data Structures
        • Lists
        • Arrays
          • Single and Multi-Dimensional Arrays
        • Lists vs Arrays
          • Activities
        • Tuples
        • Sets
        • Dictionaries
          • Activities
      • File Handling
        • Loops, Lists, Dictionaries
        • Activities
  • 3 - Theory Content
    • Theory Content Explained
      • NESA Directional Verbs
      • Responding to Directional Verbs
  • 4 - Software Development and Management
    • Approaches to Software Development
      • Waterfall Model
      • Agile Model
      • Summary: Waterfall vs Agile
      • Activities
    • Software Development Steps
      • Sample Exam Question
      • Requirements Definition
        • Understanding the Need
        • Key Questions to Ask
        • Examples
        • Activities
        • Sample Exam Question
      • Determining Specifications
        • Functional Specifications
        • Non-Functional Specifications
        • Activities
      • Design
        • Top-Down Design Approach
        • Bottom-Up Design Approach
      • Development
        • Optimising Code
      • Integration
        • Example: Payment Program
        • Activity
        • Application Programming Interface (API)
          • Example: OpenWeather API
          • Example: WeatherAPI
          • Activity: Prepare Spells
      • Testing and Debugging
        • Test Data
          • Activities
        • Testing the System
          • Activities
        • Debugging
          • Types of Errors
            • Activities
          • Python Debugger
            • Activities
          • VS Code Debugger
            • Activities
      • Installation
        • Activities
        • Sample Exam Question
      • Maintenance
  • Charts and Algorithms
    • Example: IPO Charts and Pseudocode
      • Activities
    • Algorithms, Flowcharts, Pseudocode
      • Pseudocode Activities
      • Flowchart Activities
      • Sample Exam Questions
    • Structure Charts
      • Activities
      • Sample Exam Questions
    • Data Flow Diagrams
      • Activities
    • Data Dictionaries
      • Activities
    • Decision Trees
      • Activities
      • Sample Exam Questions
    • Gantt Chart
    • Class Diagrams
      • Sample Exam Question
    • Storyboards
      • Sample Exam Question
  • Testing and Debugging
    • Test Data
      • Activities
    • Testing the System
      • Activities
    • Debugging
      • Types of Errors
        • Activities
      • Python Debugger
        • Activities
      • VS Code Debugger
        • Activities
  • Computational Thinking
    • Decomposition
    • Abstraction
    • Activities
  • Version Control
    • Git
    • GitHub
    • Activities
  • Number Systems
    • Binary Systems
    • Hexadecimal Numbers
    • Using Two's Complement
    • Activities
  • 5 - Assessment Task 1
    • Data Science Project
      • Before we Start
        • Setting up GitHub Repository
        • Setting Up Markdown Documentation
      • Examples of API Usage
        • Starter Code: NASA Scenario
        • Starter Code: Spell Book
        • Starter: Pokédex Explorer
        • Starter Code: Weather App
        • Example: OpenWeather API
        • Example: WeatherAPI
        • Example: Prepare Spells
    • Task Guide
      • Requirements Definition
      • Determining Specifications
        • Use Cases
      • Design
        • Gantt Chart
        • Structure Chart
        • Algorithms
        • Data Dictionary
      • Development
        • Comments vs DocStrings
        • UI - main.py
        • Create Python Module
          • Example: NASA Module
          • Example: WeatherFetch Module
          • Example: SpellBook Module
      • Integration
        • Example: Pokedex
      • Testing and Debugging
        • Commit Changes
      • Installation
      • Maintenance
    • Submitting Your Task
Powered by GitBook
On this page
  1. 2 - Python
  2. Data Structures and File Management
  3. Data Structures
  4. Lists vs Arrays

Activities

PreviousLists vs ArraysNextTuples

Last updated 2 months ago

Appending an Array

Check this link:

Create a Folder and open in VS code. Create and complete the following programs:

1 - Basic_List_Operations.py
# 1. Create a list named 'students' with at least 4 student names.
students = ['Alice', 'Bob', 'Charlie', 'Diana']

# 2. Print the first and last student's name using indexing.
# Remember that the first item has an index of 0.

# 3. Add a new student to the end of the list.
# Use append() to add a new name to the list.

# 4. Remove the second student from the list.
# Use pop()to delete an element by index.

# 5. Print the updated list.

2 - Array_Module.py
import array  # Import the array module

# 1. Create an array named 'scores' that stores five test scores (integers).
scores = array.array('i', [85, 90, 88, 92, 87])

# 2. Print the third score in the array.
# Arrays use indexing just like lists.

# 3. Change the second score to a new value.
# Modify an element by accessing it through its index.

# 4. Add a new score to the array.
# Use append() to add a new element.

# 5. Print the updated array.
# Should show: array('i', [85, 95, 88, 92, 87, 93])

3 - Nested_List_or_Matrix.py
# 1. Create a nested list named 'grades' where each inner list represents a student.
#    Each student should have grades for Math, Science, and English.
grades = [
    [85, 90, 88],  # Student 1's grades: Math, Science, English
    [78, 82, 85],  # Student 2's grades: Math, Science, English
    [92, 89, 91]   # Student 3's grades: Math, Science, English
]

# 2. Print the grades of the second student.
# Access the second student (index 1), then print their grades.

# 3. Change the Math grade of the first student.
# Modify the first grade in the first student's list.

# 4. Add a new student with grades.
# Add a new list to the 'grades' list to represent a new student's grades.

# 5. Print the updated list.

4 - Multidimensional_Arrays.py
import numpy as np  # Import NumPy library

# 1. Create a 2D NumPy array named 'matrix' with 3 rows and 3 columns of numbers.
matrix = np.array([
    [1, 2, 3],
    [4, 5, 6],
    [7, 8, 9]
])

# 2. Print the entire second row.
# The second row is at index 1 (remember, indexing starts at 0).
# Output will be [4, 5, 6]

# 3. Change the value in the first row, second column.
# The first row is at index 0, second column is at index 1.


# 4. Add a new row to the matrix.
# Use np.append to add a row to the existing matrix.
# use this code: new_row = np.array([10, 11, 12])
# use this code: matrix = np.append(matrix, [new_row], axis=0)

# 5. Print the updated matrix.

5 - sales_array.py

Use arrays to store and manipulate the following monthly sales revenue (dollars) for a company over two years.

Year

January

February

March

April

May

June

July

August

September

October

November

December

2015

1000

1100

1200

1300

1400

1500

1600

1700

1800

1900

2000

2100

2016

1050

1150

1250

1350

1450

1550

1650

1750

1850

1950

2050

2150

import numpy as np  # Import NumPy library

# 1. Create a 2D NumPy array to represent sales data for each year.
# Each row represents a year, and each column represents a month's sales.

sales_data = np.array([
    [1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000, 2100],  # 2015 sales data
    [1050, 1150, 1250, 1350, 1450, 1550, 1650, 1750, 1850, 1950, 2050, 2150],  # 2016 sales data
])

# 2. Print the sales for the second year (index 1).
 # Output will be the sales for 2016

# 3. Change the sales for July in the first year (2015) to a new value.
# Set July sales for 2015 to 1650

# 4. Add a new row for another year (2017).
# Note: NumPy arrays have fixed size, so to add new rows, use np.append or recreate the array.

# 5. Print the updated sales data.

NOTE: To append an array:

6 - contact_list.py

Use lists to store and manipulate a contact list for a phone app. Each contact has a name, phone number, and email address.

Name

Phone Number

Email Address

Alice

555-1234

Bob

555-5678

Charlie

555-8765

Diana

555-4321

# 1. Create a list named 'contacts' with at least 4 contacts.
# Each contact will be represented as a list with name, phone, and email.

contacts = [
    ['Alice', '555-1234', 'alice@email.com'],
    ['Bob', '555-5678', 'bob@email.com'],
    ['Charlie', '555-8765', 'charlie@email.com'],
    ['Diana', '555-4321', 'diana@email.com']
]

# 2. Print the details of the second contact.
# Output will be: ['Bob', '555-5678', 'bob@email.com']

# 3. Update the phone number of the third contact.

# 4. Add a new contact to the list.

# 5. Print the updated contact list.

https://www.tutorialspoint.com/numpy/numpy_append.htm
https://www.tutorialspoint.com/numpy/numpy_append.htm
alice@email.com
bob@email.com
charlie@email.com
diana@email.com