7.1 Programming language is a set of instructions.
Programming is the processing of instructions step by step to do specific tasks.
Programmer is coder, Software developer, software engineer who writes, tests, debugs and maintains the source code.
7.2 Types of programming language:
High level programming language is source code.
Low level programming language is compiled machine code.
7.3 Programming tools
Algorithm is a pseudocode "pronounce sudo-code" that guides a computer on how to solve a problem.
Flowchart is visual diagram of an algorithm.
7.4 Coding is writing instructions, Testing is checking for mistakes. Debugging is fixing them.
7.5 Compiler translates at once and display error at end. Interpreter translate line-by-line and display errors.
7.6 Python: Guido Van Rossum in 1991 and uses in web development, data science, machine learning, AI etc.
Features: Easy to read, write, versatile, beginner friendly.
7.7 Comment syntax
#Single line
''' Tripple single quote as multi-line '''
7.8 I/O statement. Name=input("Name:")
a,b,c=input("Enter three String as space/,/-").split( /","/"-")
x,y,z = map(int, input (" Three Numbers by space: ").split())
s=x+y+z
print(f"Given numbers: {x},{y},{z} Sum={s}")
n = [int(n) for n in input('Input any numbers with, to sum').split(",")]
print(n)
s=sum(n)
print(s)
print(sum([int(n) for n in input("Input any numbers with, to sum ").split(',')]))
A,B,C=(1,2,3)
X,Y,Z=1,"Hi",True
SWAP N=[1,2] =>N[0], N[1] =N[1],N[0] =>N=[2,1]
Print("Hello")
If name="Ram" & age=25
print("Name is %s and old %d." %(name,age)
print("Name is {} and old {}." .format(name,age))
print(f"Name is {name} and old {age}.")
7.9 Data types and variables
int, float, str, bool, a=5, b=1.2, name="Ram"
7.10 Type casting
a. Automatic type conversion
x=10, y=5.5, x=x+y print(z)
b. Intentionally
x=4.5, int(x) print(x); x=4, float(x) print(x)
7.11 Operators and expressions
1. Arithmetic: +,-,*,/,%,**
2. Relational: ==,!=,>,<,>=,<=
3. Logical: AND, OR, NOT
4.Assignment:=,+=,-,*=, /=,%=,**=
5. Expression: I= (p*t*r)/100
e.g: a=float(input("a="))
b=float(input(b="))
c=a+b
print(f"a={a}, b={b} & c={c}.")
7.12 Conditional statement
1. if condition: ... ... ...
2. if condition: ... ... ... else
3.if c1: ...elif c2: ... else..
e.g. n=int(input("n="))
if n>0:
print("+ve")
elif n==0:
print("zero")
else:
print("-ve")
OR n=int(input("n="))
print("+ve" if n>0
else "zero" if n==0
else "-ve)
7.13 Iteration
1. for item in sequence:
e.g. for x in range(5): print(x)
2. if condition: ..else: pass
3. for number in range(1,6):
if number==3: continue print(number)
4. for number in range(1,6):
if number==3: break print(number)
5. While condition:
e.g. count=1
While count<=5:
(4space)print (count)
(4space)count+=1
7.14 Python list and Dictionary
Mylist=["CS","Sc", 20, True]
print (Mylist), print(len(Mylist))
mydict={"Student":"Pen", "Teacher":"Marker", "Tailer:"Needle"}
print(mydict)
7.15 Use of library
String Methods
# center()
print("hello".center(10, '*'))**hello***
# upper()
print("Hello".upper()HELLO
# lower()
print("Hello".lower()hello
Built-in Functions
# len()
print(len("world"))5
# sum()
print(sum([1, 2, 3]))6
# abs()
print(abs(-5))5
# round()
print(round(3.14159, 2))3.14
# max()
print(max([1, 5, 2])) 5
# min()
print(min([1, 5, 2])) 1
math Module Functions
import math
# math.sqrt()
print(math.sqrt(9)) 3.0
# math.ceil()
print(math.ceil(4.2)) 5
# math.floor()
print(math.floor(4.8))4
# math.factorial()
print(math.factorial(4)) 24
# math.pow()
print(math.pow(2, 3)) 8.0
# math.sin()
print(math.sin(math.pi / 2)) 1.0
# math.log()
print(math.log(100, 10)) 2.0
Practical Task
8 Download and install python
9 Setup IDE and customize interface.
10 Demonstrate the use of I/O statements.
11 Demonstrate the concept of constant, variable and data types.
12 Demonstrate the use of various operators.
13 Demonstrate the use of if, if else and elif.
14 Demonstrate the use of for loop
15 Demonstrate the use of while loop
16 Demonstrate the list Demonstrate the directory with relevant example.
17 Demonstrate and use string functions and mathematical functions
Project work
a) Develop a simple real life project using Python programming and libraries such as
calculators, mathematical operations, etc
Practical Activities
• Download and install the latest version of the Python program at
https://www.python.org/downloads/.
• Select and install any Python IDEs and code editors such as IDLE, Jupyter,
Sublime Text, PyCharm, Visual Studio Code, or similar tools.
• Use Python's interactive shell to demonstrate live coding, allowing students
to experiment with code snippets and see immediate results.
• Discuss the programming logic development tools and group work to
develop a flowchart and algorithm.
• Demonstrate each programming concept with syntax and code.
• Document each programming code for internal and practical evaluation