Professional Documents
Culture Documents
: 1
Date : STRUCTURED PROGRAMMING
PARADIGM
AIM :
PSEUDOCODE:
18CSC207J
OUTPUT:
Fibonacci sequence:
18CSC207J
Program:
n1, n2 = 0, 1
count = 0
if nterms <= 0:
elif nterms == 1:
print(n1)
else:
print("Fibonacci sequence:")
print(n1)
nth = n1 + n2
n1 = n2
n2 = nth
count += 1
Result:
18CSC207J
18CSC207J
AIM :
PSEUDOCODE:
18CSC207J
OUTPUT:
if num % 2 == 0:
else:
Result:
18CSC207J
AIM :
PSEUDOCODE:
18CSC207J
OUTPUT:
Press C - Cricket
H - Hokey: C
Result:
18CSC207J
AIM :
PSEUDOCODE:
18CSC207J
OUTPUT:
Aston
Audi
McLaren
Program 4:
i =0
for i in range(len(cars)):
print(cars[i])
i += 1
Result:
Ex. No.: 2
Date:
PROCEDURAL PROGRAMMING
PARADIGM
AIM :
PSEUDOCODE:
18CSC207J
OUTPUT:
Area of Square : 16
Area of Rectangle :
12 Area of Triangle :
15.0
18CSC207J
Programs:
def areasquare(x):
return x*x
def arearect(a,b):
return a*b
def areatri(a,b):
return (a*b)/2
print(areasquare(4))
print(arearect(3,4))
print(areatri(5,6))
Result:
18CSC207J
18CSC207J
AIM:
PSEUDOCODE:
18CSC207J
OUTPUT:
The factorial of 4 is 24
Program 2:
def calc_factorial(x):
if x == 1:
return 1
else:
return (x * calc_factorial(x-1))
num = 4
Result:
18CSC207J
AIM:
PSEUDOCODE:
18CSC207J
OUTPUT:
3
Program 3:
temp = x;
x = y;
y = temp;
x=2
y=3
swap(x, y)
print(x)
print(y)
Result:
18CSC207J
AIM:
PSEUDOCODE:
18CSC207J
OUTPUT:
4
Program 4:
def absolute_value(num):
if num >= 0:
return num
else:
return -
num
print(absolute_value(2))
print(absolute_value(-4))
Result:
Ex. No.: 3 OBJECT ORIENTED PROGRAMMING PARADIGM
Date:
AIM:
PSEUDOCODE:
18CSC207J
OUTPUT: 1
100
50
40
90
18CSC207J
Program: 1
class BankAccount:
def init (self):
self.balance = 0
a = BankAccount()
b = BankAccount()
print(a.deposit(100))
print(b.deposit(50))
print(b.withdraw(10))
print(a.withdraw(10))
Result:
18CSC207J
18CSC207J
AIM:
PSEUDOCODE:
18CSC207J
OUTPUT: 2
SURYA PRAKASH
18
True
Program 2:
class Student:
def init (self, name, id, age):
self.name = name
self.id = id
self.age = age
Result:
18CSC207J
AIM:
PSEUDOCODE:
18CSC207J
OUTPUT:
class Person:
def init (self, name, age):
self.name = name
self.age = age
def myfunc(self):
print("Hello my name is " + self.name)
print("Iam "+self.age+" years old!")
p1 = Person(name, age)
p1.myfunc()
Result:
18CSC207J
AIM:
PSEUDOCODE:
18CSC207J
OUTPUT 4 :
Area of Square: 25
class Square:
side=5
def calculate_area(self):
return self.side * self.side
class Triangle:
base=5
height=4
def calculate_area(self):
return 0.5*self.base * self.height
sq=Square()
tri=Triangle()
print(“Area of Square:”, sq. calculate_area())
print(“Area of Triangle:”, tri.
calculate_area())
Result:
Ex. No.: 4 EVENT DRIVEN PROGRAMMING PARADIGM
Date :
AIM:
PSEUDOCODE:
18CSC207J
OUTPUT 1 :
leftclick
rightclick
middleclick
18CSC207J
Program 1 :
import tkinter as tk
from tkinter import *
root=tk.Tk()
def rightclick(event):
print("rightclick")
def leftclick(event):
print("leftclick")
def middleclick(event):
print("middleclick")
frame=Frame(root,width=300,height=200)
frame.bind('<Button-1>',leftclick)
frame.bind('<Button-2>',middleclick)
frame.bind('<Button-3>',rightclick)
frame.pack()
root.mainloop()
Result:
18CSC207J
AIM:
PSEUDOCODE:
18CSC207J
OUTPUT 2
7 event (x=84,
y=1)
7 event (x=34,
y=-1)
18CSC207J
Program 2 :
class App(tk.Tk):
def init (self):
super(). init ()
frame = tk.Frame(self, bg="green", height=100, width=100)
frame.bind("<Button-1>", self.print_event)
frame.bind("<Double-Button-1>", self.print_event)
frame.bind("<ButtonRelease-1>", self.print_event)
frame.bind("<B1-Motion>", self.print_event)
frame.bind("<Enter>", self.print_event)
frame.bind("<Leave>", self.print_event)
frame.pack(padx=50, pady=50)
Result:
18CSC207J
AIM:
PSEUDOCODE:
18CSC207J
OUTPUT 3 :
clicked at 1 47
pressed 'f'
pressed 'f'
pressed 'n'
pressed 'j'
pressed 'g'
pressed 'f'
pressed ''
pressed ''
18CSC207J
Program 3 :
root = Tk()
def key(event):
print("pressed", repr(event.char))
def callback(event):
frame.focus_set()
print("clicked at", event.x, event.y)
frame = Frame(root, width=100,
height=100) frame.bind("<Key>", key)
frame.bind("<Button-1>", callback)
frame.pack()
root.mainloop()
Result:
18CSC207J
AIM:
PSEUDOCODE:
18CSC207J
OUTPUT 4 :
18CSC207J
Program 4 :
import tkinter as tk
class App(tk.Tk):
def init (self):
super(). init ()
entry = tk.Entry(self)
entry.bind("<FocusIn>", self.print_type)
entry.bind("<Key>", self.print_key)
entry.pack(padx=20, pady=20)
Result:
18CSC207J
Ex. No.: 5 DECLARATIVE PROGRAMMING PARADIGM
Date :
AIM:
PSEUDOCODE:
18CSC207J
OUTPUT 1 :
18CSC207J
Program 1 :
import sqlite3
con = sqlite3.connect('Students.db')
c=con.cursor()
con.commit()
Result:
18CSC207J
AIM:
PSEUDOCODE:
18CSC207J
OUTPUT :
18CSC207J
Program:
import sqlite3
con = sqlite3.connect("file3.db")
c = con.cursor()
con.commit()
task = '''SELECT t1.name,t2.job FROM t1,t2 WHERE t1.id =
t2.id;''' for row in c.execute(task):
print(row)
Result:
18CSC207J
AIM:
PSEUDOCODE:
18CSC207J
OUTPUT :
Initial table:
Table is now:
Table is now:
18CSC207J
Program:
import sqlite3
con = sqlite3.connect('file4.db')
c = con.cursor()
def printall():
global c
for row in c.execute("SELECT * FROM datatable"):
print(row)
namelist = [(1,'Aman'),(2,'Aviraj'),(3,'Venkat')]
c.executemany("INSERT INTO datatable VALUES(?,?)",namelist)
con.commit()
Result:
18CSC207J
18CSC207J
AIM:
PSEUDOCODE:
18CSC207J
OUTPUT:
Opened database
successfully Opened
database successfully
Opened database
successfully ID = 1
NAME = Paul
ADDRESS = California
SALARY = 20000.0
ID = 2
NAME = Allen
ADDRESS = Texas
SALARY = 15000.0
ID = 3
NAME = Teddy
ADDRESS =
Norway SALARY =
20000.0
ID = 4
NAME = Mark
ADDRESS = Rich-Mond
SALARY = 65000.0
18CSC207J
Operation done successfully
18CSC207J
Program:
import sqlite3
conn = sqlite3.connect('test.db')
conn = sqlite3.connect('test.db')
print ("Opened database successfully")
import sqlite3
conn = sqlite3.connect('test.db')
print ("Opened database successfully")
conn.commit()
print ("Records created successfully")
conn.close()
import sqlite3
conn = sqlite3.connect('test.db')
print("Opened database successfully") 18CSC207J
Opened database
successfully ID = 1
NAME = Nabhan
AGE= 19
ADDRESS = Vellore
SALARY = 20000.0
ID = 2
NAME = Allen
AGE= 25
ADDRESS = Texas
SALARY = 15000.0
ID = 3
NAME =
Teddy AGE=
23
ADDRESS =
Norway SALARY =
20000.0
ID = 4
NAME = Mark
AGE= 25
ADDRESS = Rich-Mond
SALARY = 65000.0
18CSC207J
Total number of rows updated :
1 ID = 1
18CSC207J
cursor = conn.execute("SELECT id, name, address, salary from
COMPANY") for row in cursor:
print ("ID = ", row[0])
print ("NAME = ", row[1])
print ("ADDRESS = ", row[2])
print ("SALARY = ", row[3], "\n")
import sqlite3
conn = sqlite3.connect('test.db')
print("Opened database successfully")
conn.execute('''CREATE TABLE
COMPANY12345 (ID INT PRIMARY KEY NOT
NULL,
NAME TEXT NOT NULL,
AGE INT NOT NULL,
ADDRESS CHAR(50),
SALARY REAL);''')
print("Table created successfully")
conn.commit()
print("Records created successfully")
cursor = conn.execute("SELECT ID,NAME,AGE,ADDRESS,SALARY from
COMPANY12345")
for row in cursor:
print("ID = ", row[0])
print("NAME = ", row[1])
print("AGE=", row[2])
print("ADDRESS = ", row[3])
print("SALARY = ", row[4])
18CSC207J
NAME = Paul
ADDRESS = California
SALARY = 25000.0
ID = 2
NAME = Allen
ADDRESS = Texas
SALARY = 15000.0
ID = 3
NAME = Teddy
ADDRESS =
Norway SALARY =
20000.0
ID = 4
NAME = Mark
ADDRESS = Rich-Mond
SALARY = 65000.0
1 ID = 1
NAME = Paul
ADDRESS = California
SALARY = 25000.0
18CSC207J
import sqlite3
conn = sqlite3.connect('test.db')
print("Opened database successfully")
import sqlite3
conn = sqlite3.connect('test.db')
print( "Opened database successfully")
18CSC207J
ID = 3
NAME = Teddy
ADDRESS =
Norway SALARY =
20000.0
ID = 4
NAME = Mark
ADDRESS = Rich-Mond
SALARY = 65000.0
18CSC207J
Result:
Ex. No.: 6 IMPERATIVE PROGRAMMING PARADIGM
Date :
AIM:
PSEUDOCODE:
18CSC207J
18CSC207J
OUTPUT:
15
Program:
my_list = [1, 2, 3, 4, 5]
sum = 0
for x in my_list:
sum += x
print(sum)
Result:
AIM:
PSEUDOCODE:
18CSC207J
18CSC207J
OUTPUT:
python
Program:
sample_characters = ["p","y","t","h","o","n"]
sample_string = ''
sample_string
sample_string = sample_string + sample_characters[0]
sample_string ="p"
sample_string = sample_string + sample_characters[1]
sample_string ="py"
sample_string = sample_string + sample_characters[2]
sample_string ="pyt"
sample_string = sample_string + sample_characters[3]
sample_string ="pyth"
sample_string = sample_string + sample_characters[4]
sample_string ="pytho"
sample_string = sample_string + sample_characters[5]
sample_string ="python"
print(sample_string)
Result:
AIM:
PSEUDOCODE:
18CSC207J
18CSC207J
OUTPUT:
we
wel
welc
welco
welcom
welcome
Program:
sample_characters = ["w","e","l","c","o","m","e"]
sample_string = ''
sample_string
for c in sample_characters:
sample_string = sample_string + c
print(sample_string)
Result:
AIM:
PSEUDOCODE:
18CSC207J
18CSC207J
OUTPUT:
10 2 5.0
10 5 2.0
10 is a prime number
11 is a prime number
12 2 6.0
12 3 4.0
12 4 3.0
12 6 2.0
12 is a prime number
13 is a prime number
14 2 7.0
14 7 2.0
14 is a prime number
15 3 5.0
15 5 3.0
15 is a prime number
16 2 8.0
16 4 4.0
16 8 2.0
16 is a prime number
17 is a prime number
18 2 9.0
18 3 6.0
18 6 3.0
18 9 2.0
18 is a prime number
Program:
Result: