Chapter4 Programmingelement
Chapter4 Programmingelement
PYTHON
PROGRAMMING
ELEMENT
VARIABLE AND RESERVE WORDS
totalSales Yes
total_Sales Yes
total.Sales No
4thQtrSales No
totalSale$ No
DATA TYPE
• Data types in programming can be defined as a collection of
data values and a set of predefined operators on those
Numeric
Data type
values.
• Based on the data type of a variable, the interpreter
allocated memory and decides what can be stored in the
reserved memory.
String
Boolean
NUMERIC DATA TYPE-INT
• Plain integers of positive or negative whole numbers
• E.g. : 10, -10
• Assign for suitable variable application, such as number of student
(num_student), number of car (num_car) and etc.
• E.g.
12.45 -3.8
For example:
Data type set by the programmer is int, therefore
If the user key in score as 5.5, error will be appear.
• Once the input value has been processed, e.g after it underwent a series of arithmetic calculation, the
output result should be displayed on the computer screen.
• To display output, the programmer uses the print ( ) function, with argument in the bracket.
• We can improvise our program by creating more argument in the block of print ( ) function.
• To write this statement, a string element is needed as part of the argument together with the variable in
the block of ( ) function, as shown below:
..Continue
• For example:
• a = b + c This is arithmetic expression
• i > j Boolean Expression
• mark > = 0 and marks <= 100 Compound Boolean expression
• An operator is define as a symbol that tells the programming interpreter in this
case Python language to perform mathematical or constructing Boolean expression
• There are 4 main categories of operators;
(1) Arithmetic Operator
Operators Name
+ Additional
- Subtraction
* Multiplication
/ Division
% Modulus
Operators Name
= Assignment
(3) Relational Operator – Text or defining relationship of two variables
Operators Name
== Equal to
> Greater than
< Less than
>== Greater than or equal to
<== Less than or equal to
!= Not equal to
Function Description
sqrt (x) Return the square root of x
pow (x,y) Return value of x to the power of y
sin (x) Return the sine value of x
cos (x) Return the cos value of x
pi The mathematical constant pi (3.14159..)
degree (x) Converts angle x from radians to degrees
radians (x) Convers angle x from degrees to radians
Must call this import math library that
contain function