0% found this document useful (0 votes)
7 views14 pages

201 Last Note

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

201 Last Note

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

THERE ARE 7 CATEGORIES OF COMPUTER LANGUAGES:

1. MACHINE AND ASSEMBLY LANGUAGES


2. ALGORITHMIC LANGUAGES
3. BUSINESS-ORIENTED LANGUAGES
4. DECLARATIVE LANGUAGES
5. EDUCATION-ORIENTED LANGUAGES
6. OBJECT-ORIENTED LANGUAGES
7. WORLD WIDE WEB DISPLAY LANGUAGES.

1. MACHINE AND ASSEMBLY LANGUAGES


A machine language consists of the numeric codes for
the operations that a particular computer can execute
directly. The codes are strings of 0s and 1s,
or binary digits (“bits”). Machine language is difficult to
read and write, since it does not resemble
conventional mathematical notation or human
language, and its codes vary from computer to
computer.
Assembly language is one level above machine
language. Assembly language is designed to be easily
translated into machine language. Like machine
language, assembly language requires detailed
knowledge of internal computer architecture. It is
useful when such details are important, such
as programming a computer to interact with peripheral
devices (printers, scanners, storage devices, and so
forth).
Difference Between Machine Language and Assembly Language
Parameters Machine Language Assembly Language

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.

3 Programming Language Generation The assembly languages are second-


gen languages.
The machine languages are first-
gen languages.

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.

7. WORLD WIDE WEB DISPLAY LANGUAGES


The World Wide Web is a system for displaying text,
graphics, and audio retrieved over the Internet on a
computer monitor. Each retrieval unit is known as a
Web page, and such pages frequently contain “links”
that allow related pages to be
retrieved. HTML (hypertext markup language) is
the markup language for encoding Web pages. Othe
examples are XML (extensible markup language) and
Web scripting.

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'>

One value to multiple variables


X = y = z = "orange"
Print(x)
Print(y)
Print(z)
Many values to multiple variables in a single line
X, y, z = "orange", "banana", "cherry"
Print(x)
Print(y)
Print(z)

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

PYTHON DATA TYPES


Variables can store data of different types and Python has the following data
types built-in by default.
print(type(x))

EXAMPLE DATA TYPE

x = "hello world" STR

x = 20 INT

x = 20.5 FLOAT

x = 1j COMPLEX

x = ["apple", "banana", "cherry"] LIST

x = ("apple", "banana", "cherry") TUPLE


x = range(6) RANGE

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

#convert from int to float:


a = float(x)

#convert from float to int:


b = int(y)

#convert from int to complex:


c = complex(x)
print(a)
print(b)
print(c)

Assign String to a Variable


strings in Python are arrays of bytes

a = "Hello"
print(a)

a = "Hello, World!"
print(a[1])

output : e

Python Booleans

Booleans represent one of two values as either True or False.

In programming you often need to know if an expression is True or False

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

Operators are used to perform operations on variables and values.

Python divides the operators in the following groups:

 Arithmetic operators ( + - + / % **)

x=2
y=5
print(x ** y) #same as 2*2*2*2*2

 Assignment operators (= += -= *= /= **=)

x=5
x **= 3
print(x)

 Comparison operators (== != > < >= <=)

x=5

y=3

print(x >= y) # returns True because five is greater, or equal, to 3

 Logical operators (and or not)

x=5
print(not(x > 3 and x < 10))

# returns False because not is used to reverse the result

print(x > 3 or x < 4)

# returns True because one of the conditions are true (5 is greater


than 3, but 5 is not less than 4)

print(x > 3 and x < 10)

# returns True because 5 is greater than 3 AND 5 is less than 10

 Identity operators (is, is not)

is Returns True if both variables are the same object


x is y

Is not Returns True if both variables are not the same


object

x = ["apple", "banana"]

y = ["apple", "banana"]

z=x

print(x is z)

# returns True because z is the same object as x

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)

# to demonstrate the difference betweeen "is" and "==": this comparison


returns True because x is equal to y

Output:
True
False
True

 Membership operators (in not in)

in Returns True if a sequence with the specified value is present in the


object x in y

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"]

print ("pineapple" not in x)

# returns True because a sequence with the value "pineapple" is not in


the list

Output = True

Python Conditions and If statements


Python supports the usual logical conditions from mathematics:

 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

Python relies on indentation (whitespace at the beginning of a line) to define


scope in the code. An If statement without indentation will raise an error.

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.")

You might also like