201 Last Note
201 Last Note
1 Nature of The machine languages consist of The assembly languages have a similar
Syntax 1s and 0s as binary digits. syntax to that of the English language-
thus making it easy for general users
to understand.
2 Ease of Only computers can comprehend It is very easy for any human to
Understanding machine languages. A normal understand, apply, and use assembly
human doesn’t possess the language.
capacity to decipher it.
4 Dependency All machine languages are The assembly languages are machine-
dependent on hardware. dependent. They are, thus, not
portable.
5 Risk of Errors There is a higher risk of errors in There is a comparatively lower risk of
the syntax of any machine errors in the syntax of an assembly
language, in general. language in use.
2. ALGORITHMIC LANGUAGES
Algorithmic languages are designed to express
mathematical or symbolic computations. They can
express algebraic operations in notation similar to
mathematics and allow the use of subprograms that
package commonly used operations for reuse. They
were the first high-level languages. e.g., FORTRAN,
ALGOL and C.
3. BUSINESS-ORIENTED LANGUAGES
COBOL (common business-oriented language) has been
heavily used by businesses since its inception in 1959.
A committee of computer manufacturers and users and
U.S. government organizations established CODASYL
(Committee on Data Systems and Languages) to
develop and oversee the language standard in order to
ensure its transferrable across diverse systems.
Another example of business-oriented language is SQL
(structured query language).
4. DECLARATIVE LANGUAGES
Declarative languages, also called nonprocedural or
very high level, are programming languages in which
(ideally) a program specifies what is to be done rather
than how to do it. In such languages there is less
difference between the specification of a program and
its implementation than in the procedural languages
described so far. The two common kinds of declarative
languages are logic and functional languages.
5.EDUCATION-ORIENTED LANGUAGES
BASIC (beginner’s all-purpose symbolic instruction
code) It was intended to be easy to learn by novices,
particularly non-computer science majors, and to run
well on a time-sharing computer with many users. It
had simple data structures and notation and it was
interpreted. a BASIC program was translated line-by-
line and executed as it was translated, which made it
easy to locate programming errors. Other examples of
Education-oriented languages are Pascal, Logo and
Hypertalk.
6. OBJECT-ORIENTED LANGUAGES
Object-oriented languages help to manage complexity
in large programs. Objects package data and the
operations on them so that only the operations are
publicly accessible and internal details of the data
structures are hidden. Other examples of Object-
oriented languages are Smalltalk, C++, C#, Ada, Java,
Visual Basic and python.
PYTHON COMMENTS
Comments starts with a #
Comments can be used to explain Python code.
Comments can be used to prevent execution when testing code. E.g
#THIS IS A COMMENT
PRINT ("WE HAVE A CLASS!")
PYTHON VARIABLES
Variables are containers for storing data values. A variable is created the
moment you first assign a value to it.
1. X=5
Y = "john"
Print(x)…….5
Print(y)……john
2. X = 4 # x is of type int
X = "sally" # x is now of type str
Print(x)……………… sally.
3. You can get the data type of a variable with the type() function.
Example
X=5
Y = "john"
Print(type(x)) ………………. <class 'int'>
Print(type(y)) ……………… <class 'str'>
OUTPUT VARIABLES
The python print() function is often used to output variables.
x = "python "
y = "is "
z = "awesome"
print (x + y + z) …………………... python is awesome.
INPUT FUNCTION
print ("hello world")
x=input("enter a no: ")
y=input("enter anoda no: ")
z=int(x) + int(y)
print (z)
#leave this
x = 20 INT
x = 20.5 FLOAT
x = 1j COMPLEX
x = true BOOL
List and Tuple in Python are the classes of Python Data Structures.
The list is dynamic, whereas the tuple has static characteristics.
This means that lists can be modified whereas tuples cannot be
modified.
# creating a list with ARRAY
# the use of numbers 1 0
# code to test that tuples are mutable 2 1
list = [1, 2, 4, 4, 3, 3, 3, 6, 5] 4 2
print("original list ", list) 4 3
3 4
list[3] = 77 3 5
print("example to show mutability ", list) 3 6
6 7
Original list [1, 2, 4, 4, 3, 3, 3, 6, 5] 5 8
Example to show mutability [1, 2, 4, 77, 3, 3, 3, 6, 95]
TUPLE
# code to test that tuples are immutable
tuple1 = (0, 1, 2, 3)
tuple1[0] = 4
print(tuple1)
Output:
Traceback (most recent call last):
File "e0eaddff843a8695575daec34506f126.py", line 3, in
tuple1[0]=4
TypeError: 'tuple' object does not support item assignment
Python Numbers
There are three numeric types in Python:
int
float
complex
x = 1 # int
y = 2.8 # float
z = 1j # complex
a = "Hello"
print(a)
a = "Hello, World!"
print(a[1])
output : e
Python Booleans
When you compare two values, the expression is evaluated and Python
returns the Boolean answer.
print(10 > 9)
print(10 == 9)
print(10 < 9)
True
False
False
x = "Hello"
y = 15
print(bool(x))
print(bool(y))
True
True
Python Operators
x=2
y=5
print(x ** y) #same as 2*2*2*2*2
x=5
x **= 3
print(x)
x=5
y=3
x=5
print(not(x > 3 and x < 10))
x = ["apple", "banana"]
y = ["apple", "banana"]
z=x
print(x is z)
print(x is y)
# returns False because x is not the same object as y, even if they have
the same content
print(x == y)
Output:
True
False
True
x = ["apple", "banana"]
print ("banana" in x)
# returns True because a sequence with the value "banana" is in the list
Output = True
not in Returns True if a sequence with the specified value is not present
in the object x not in y
x = ["apple", "banana"]
Output = True
Equals: k == p
Not Equals: k != p
Less than: k < p
Less than or equal to: k <= p
Greater than: k > p
Greater than or equal to: k >= p
If statement:
k = 4
p = 68
if p > k:
print("p is greater than k") ………………...p is greater than k
Elseif (elif)
The elif keyword means "if the previous conditions were not true, then try this
condition".
a = 65
b = 65
if b > a:
print("b is greater than a")
elif a == b:
print("a and b are equal")…………………… a and b are equal
Else
The else keyword outputs anything which isn't captured by the preceding
conditions
k = 79
p = 12
if p > k:
print("p is greater than k")
elif a == b:
print("p and k are equal")
else:
print("k is greater than p")……………… k is greater than p
And
The and keyword is used to combine conditional statements.
a = 105
b = 90
c = 150
if a > b and c > a:
print("Both conditions are True")……….. Both conditions are true
Or
The or keyword is used to combine conditional statements:
a = 105
b = 90
c = 150
if a > b or a > c:
print("At least one of the conditions is True")… Both conditions are
true
Not
The not keyword is used to reverse the result of the conditional statement:
a = 33
b = 200
if not a > b:
print("a is NOT greater than b")……... a is NOT greater than b
Nested If
You can have if statements inside if statements, this is
called nested if statements.
k = 34
if k > 8:
print("Above ten,")
if k > 20:
print("and also above 20!")
else:
print("but not above 20.")