[go: up one dir, main page]

0% found this document useful (0 votes)
231 views22 pages

COMP1117 Computer Programming

This document provides information about the COMP1117 Computer Programming course. It outlines the course learning outcomes which are computational mind, program implementation using Python, and program comprehension. It details the textbook, assessments including programming assignments and a final exam, instructors and teaching assistants. It introduces Python as the programming language and how to get Python. It explains high-level and low-level languages, interpreters and compilers, integrated development environments, and how to write and run a Python program. It also covers arithmetic operators, debugging, and different types of errors in programming.

Uploaded by

DONGHWEE CHOI
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
231 views22 pages

COMP1117 Computer Programming

This document provides information about the COMP1117 Computer Programming course. It outlines the course learning outcomes which are computational mind, program implementation using Python, and program comprehension. It details the textbook, assessments including programming assignments and a final exam, instructors and teaching assistants. It introduces Python as the programming language and how to get Python. It explains high-level and low-level languages, interpreters and compilers, integrated development environments, and how to write and run a Python program. It also covers arithmetic operators, debugging, and different types of errors in programming.

Uploaded by

DONGHWEE CHOI
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 22

COMP1117

Computer Programming

1
Outcome base learning
Outcome Descriptions
Computational mind Able to identify possible solutions for problems based on
computer programs
Program implementation Able to implement solutions using Python
Program comprehension Able to understand program by others and participate in
larger scale system implementation.

2
Details of the courses
 Textbook:
http://greenteapress.com/wp/think-python-2e/
 Assessment
 4 programming assignments (40%)
 A1 (5%), A2 (10%), A3 (10%), A4 (15%)
 Tutorial exercises (10%)
 Workshop starts from Jan 25, 2022
 Final exam (50%)
 Instructors: H.F. Ting
 TAs: Jolly Cheng, Chun Kiu Lai, Zerong Xie, Ruixing Jia and ~10 STAs

3
The Programming language Python
Created by the Dutch programmer Guido
van Rossum and first released in 1991.
You can use Python directly from your
moodle account.
You may get Python and related tools via

https://www.python.org/downloads/
Python has two different major versions Python2 and
Python3. And you should use Python3, e.g. Python 3.7.8
Warning: Python 2 and Python 3 have significant
differences.
4
High-level Languages
Common programming languages include …

C C++ Python Java Pascal Visual Basic FORTRAN


COBOL Lisp Scheme Ada

These high-level languages


resemble human languages,
are easy to read and write,
use more complicated instructions than those that the
computer can follow,
must be translated to a machine language (low level
language) program for the computer to execute
5
Low-level Languages
Machine language (strings of 0’s and 1’s)
Following is an (over-simplified) example on an instruction in
some machine language program:
0110 1001 1010 1011
may instruct the computer to add (0110) the integers stored
at memory location 1001 and 1010 and store the result at
1011.
The CPU can ONLY understand machine language.

6
Bridging the gap
Some tool is needed to convert programs written in high-level language into
machine language understood by the computer. There are two methods:
Interpreter Compiler
Translates program one Scans the entire program and translates it as a
statement at a time. whole into machine code.
Python uses interpreters. Programming language like C, C++ use
compilers.
It takes less amount of time to
analyze the source code but It takes larger amount of time to analyze the
source code but the overall execution time is
the overall execution time is comparatively faster.
slower.
Continues translating the
program until the first error is It generates the error message only after
scanning the whole program. Hence debugging
met, in which case it stops.
is comparatively hard.
Hence debugging is easy.

7
IDE
An Integrated Development Environment
(IDE) is a software that integrates the steps
of developing a program, e.g., input
program, “run” program and debug program.
When you download Python, you will also
get an IDE called IDLE (Integrated
Development and Learning Environment):
 IDLE is integrated development environment (IDE) for
editing and running Python programs.
 It has a number of features to help you develop your
Python programs including powerful syntax
highlighting.
Eg. Icon for the Python program Q4.py:

What you will see if


you open IDLE without any filename.

8
A Python Program
Below is a simple Python program hello.py

9
A Python Program All Python programs should
have the "extension" py.

Below is a simple Python program hello.py

10
A Python Program
Below is a simple Python program hello.py

A comment line.
For any line, all characters following the
character # will be ignored by the Python
interpreter.

11
A Python Program
Below is a simple Python program hello.py

Display the string (i.e., the sequence of charaters)


between the two quotes on the output window.

12
A Python Program
Below is a simple Python program hello.py

input( ) instructed the computer to read


a string, and we can refer this input string
later using this name.

13
How to run a Python Program
Two modes: script mode vs interactive mode
Script mode:
 Input the whole Python program using the editor of IDLE, and then call
the ``Python shell’’ to execute the program by clicking the “Run” button
on top of the window.
Interactive mode
 Input the Python statements in the Python shell directly (without using
its editor)
 After each statement is input, the Python shell will execute the
statement and display its result immediately.

14
Arithmetic operators
Python supports the following arithmetic operations:
 addition: +
 subtraction: -
 multiplication: *
 division: /
 floor division: //
 modulus: %
 exponent: **
Under the interactive mode, together with these arithmetic
operators, you have a super-calculator.

15
Arithmetic operators

Challenge: Find out what "floor division", "modulus",


"exponent" operators mean.

16
More math

17
Testing & Debugging
A mistake in a program is called a bug, and the process of
eliminating bugs is called debugging

18
Three kinds of program errors
1. Syntax errors
2. Run-time errors
3. Logic errors

19
Syntax Errors
Errors resulting from violation of the syntax (i.e., the grammar
rules) of the programming language

20
Run-time Errors
Errors occur during the execution of a program
Many run-time errors have to do with numeric calculations
E.g., division by zero
The computer cannot
compute (12 /0) in run-
time

21
Logic Errors
 Errors due to incorrect logic flow
 Logic errors are most difficult to locate as they are not reported by the
compiler, but incorrect results may be produced
 E.g., using + mistakenly for multiplication
A wrong area is
computed

22

You might also like