Computer Programming II - SSS 2 Note
COMPUTER PROGRAMMING II
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:
- Explain the meaning of a programming language.
- Identify Python and JavaScript as programming languages.
- State important features and uses of Python.
- State important features and uses of JavaScript.
- Distinguish between Python and JavaScript.
- 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 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 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")
4. Introduction to JavaScript
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>
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:
- Start.
- Enter the first number.
- Enter the second number.
- Add the two numbers.
- Display the result.
- 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:
- Open a Python programming environment or suitable online editor.
- Write a simple
print()statement. - Run the program and observe the output.
- Open a suitable HTML file or JavaScript environment.
- Write a simple JavaScript
console.log()statement. - 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.
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
- What is a programming language?
- What is Python?
- State four uses of Python.
- What is JavaScript?
- State four uses of JavaScript.
- Give two differences between Python and JavaScript.
- What is meant by syntax in programming?
- How can an algorithm be used when writing a computer program?
14. Assignment
- Write five features or uses of Python.
- Write five features or uses of JavaScript.
- Write a simple Python statement that displays your name.
- 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.
Comments
Post a Comment