Computer Programming II - SSS 2 Note

Computer Programming II - SSS 2 | CMPNOTE

COMPUTER PROGRAMMING II

Subject: Digital Technologies
Class: SSS 2
Term: Second Term
Week: 2
Topic: Computer Programming II
Duration: 80 Minutes (Double Period)

Learning Objectives

By the end of the lesson, students should be able to:

  1. Explain the meaning of a programming language.
  2. Identify Python and JavaScript as programming languages.
  3. State important features and uses of Python.
  4. State important features and uses of JavaScript.
  5. Distinguish between Python and JavaScript.
  6. Write simple introductory statements in Python and JavaScript.

1. Introduction to Programming Languages

A computer follows instructions written in a form that it can process. A programming language provides rules and commands that allow people to write instructions for computers.

Programming language is a formal language used to write instructions that a computer can execute to perform specific tasks.

Programming languages have different purposes and features. Some are commonly used for websites, while others are widely used for data analysis, artificial intelligence, mobile applications, games and general software development.

2. Introduction to Python

Python is a high-level, general-purpose programming language known for its simple and readable syntax.

Python is widely used in education because its syntax is relatively easy for beginners to understand. It is also used in many professional areas of computing.

Features of Python

  • It has relatively simple and readable syntax.
  • It is a high-level programming language.
  • It supports different programming approaches.
  • It has a large collection of libraries and modules.
  • It can be used on different operating systems.
  • It is widely used for data analysis and artificial intelligence.

Uses of Python

Python can be used for:

  • General software development.
  • Web development.
  • Data analysis.
  • Artificial intelligence and machine learning.
  • Scientific and mathematical computing.
  • Automation and scripting.
  • Educational programming.

3. Simple Python Example

A simple Python program can display a message on the screen.

print("Hello, SSS 2 students!")

The print() function tells Python to display information as output.

Another simple example is:

print("Welcome to Computer Programming")
Note: Students do not need to memorise large amounts of code at this stage. The aim is to understand the basic idea of writing instructions that a programming language can execute.

4. Introduction to JavaScript

JavaScript is a programming language widely used to add interactivity and dynamic behaviour to web pages and web applications.

JavaScript commonly works together with HTML and CSS when creating websites. HTML provides the structure of a webpage, CSS controls its presentation, and JavaScript can add behaviour and interaction.

Features of JavaScript

  • It is widely used in web development.
  • It can make webpages interactive.
  • It can respond to user actions such as clicks and keyboard input.
  • It can manipulate webpage content.
  • It can run in modern web browsers.
  • It can also be used outside the browser in suitable environments.

Uses of JavaScript

  • Creating interactive webpages.
  • Developing web applications.
  • Validating information entered into forms.
  • Creating interactive menus and buttons.
  • Developing browser-based games and applications.
  • Building server-side applications using suitable JavaScript environments.

5. Simple JavaScript Example

JavaScript can display a message using the console.log() function.

console.log("Hello, SSS 2 students!");

The statement instructs JavaScript to send the message to the browser's developer console.

JavaScript can also display a message on a webpage using a suitable HTML element and script. For example:

<script>
document.write("Welcome to Computer Programming");
</script>
Programming practice: When writing code, spelling, punctuation, brackets and other syntax rules are important. A small error can prevent a program from working as expected.

6. Python and JavaScript Compared

Feature Python JavaScript
General description A general-purpose programming language. A programming language widely used for interactive web development.
Syntax Known for relatively simple and readable syntax. Uses syntax based on programming language conventions and symbols.
Common use Data analysis, AI, automation, software and web development. Webpage interaction and web application development.
Typical beginner example print("Hello") console.log("Hello");

7. Python and JavaScript in Web Development

Python and JavaScript can both be involved in web development, but they are often used differently.

JavaScript is commonly used directly in the browser to make webpages interactive. Python can be used on the server side through suitable web frameworks and can also support other parts of a web application.

A web application may therefore use more than one programming language, depending on the needs of the project.

8. Basic Programming Concepts to Remember

Although detailed programming concepts will be studied in later lessons, students should understand these basic ideas:

  • Instruction: A command given to a computer.
  • Program: A set of instructions written to perform a task.
  • Syntax: The rules that determine how instructions should be written in a programming language.
  • Output: Information produced by a program.
  • Error: A problem in a program that may cause it to produce an incorrect result or fail to run.

9. From Algorithm to Program

The algorithm studied in Week 1 provides a plan for solving a problem. A programmer can then translate the steps of the algorithm into a programming language.

Example

Problem: Display the sum of two numbers.

Algorithm:

  1. Start.
  2. Enter the first number.
  3. Enter the second number.
  4. Add the two numbers.
  5. Display the result.
  6. Stop.

Simple Python representation:

a = 5
b = 7
total = a + b
print(total)

The example shows how a planned solution can be translated into programming instructions.

10. Practical Activity

Where computers and suitable programming environments are available, students should try the following activities under teacher supervision:

  1. Open a Python programming environment or suitable online editor.
  2. Write a simple print() statement.
  3. Run the program and observe the output.
  4. Open a suitable HTML file or JavaScript environment.
  5. Write a simple JavaScript console.log() statement.
  6. Run the program and observe the result.

Students without access to a computer can write the sample programs in their notebooks and identify the expected output.

11. Common Beginner Errors

  • Misspelling programming commands.
  • Forgetting quotation marks when they are required.
  • Using incorrect brackets or punctuation.
  • Writing instructions in the wrong order.
  • Failing to check error messages.
Good programming habit: Read the error message carefully, check the line mentioned and correct the problem step by step instead of changing many parts of the program at once.

12. Summary

  • A programming language is used to write instructions for computers.
  • Python is a high-level, general-purpose programming language.
  • Python is commonly used for software development, data analysis, artificial intelligence, automation and other tasks.
  • JavaScript is widely used to make webpages and web applications interactive.
  • Python and JavaScript have different syntax and common areas of use.
  • Algorithms can be translated into programming languages.
  • Careful attention to syntax helps programmers avoid errors.

13. Evaluation Questions

  1. What is a programming language?
  2. What is Python?
  3. State four uses of Python.
  4. What is JavaScript?
  5. State four uses of JavaScript.
  6. Give two differences between Python and JavaScript.
  7. What is meant by syntax in programming?
  8. How can an algorithm be used when writing a computer program?

14. Assignment

  1. Write five features or uses of Python.
  2. Write five features or uses of JavaScript.
  3. Write a simple Python statement that displays your name.
  4. Write a JavaScript statement that displays the message "I am learning programming."

15. Interactive Revision Quiz

Choose the correct answer for each question and click Mark Quiz to see your score.

1. What is a programming language?

2. Which of the following is a programming language?

3. Which function is commonly used in Python to display output?

4. JavaScript is widely used for what purpose?

5. Which statement correctly displays a message using Python?

6. Which JavaScript command can be used to display a message in the developer console?

7. What is syntax?

8. Which of these is a common use of Python?

9. What is the relationship between an algorithm and a program?

10. Which of the following is a good programming practice?

Comments

Popular posts from this blog

Complete Computer Studies/ICT Curriculum for JSS 1 to SSS 3

90 Objective Examination Questions in Major Subjects

Number Base System