You are on page 1of 104

Ex. No.

: 1
Date : STRUCTURED PROGRAMMING
PARADIGM
AIM :

PSEUDOCODE:

18CSC207J
OUTPUT:

How many terms? 5

Fibonacci sequence:

18CSC207J
Program:

nterms = int(input("How many terms? "))

n1, n2 = 0, 1

count = 0

if nterms <= 0:

print("Please enter a positive integer")

elif nterms == 1:

print("Fibonacci sequence upto",nterms,":")

print(n1)

else:

print("Fibonacci sequence:")

while count < nterms:

print(n1)

nth = n1 + n2

n1 = n2

n2 = nth

count += 1

Result:

18CSC207J
18CSC207J
AIM :

PSEUDOCODE:

18CSC207J
OUTPUT:

Enter any number : 5

The number 5 is a Odd number


Program 2:

num = int(input('Enter any number : '))

if num % 2 == 0:

print(f'The number {num} is a Even number')

else:

print(f'The number {num} is a Odd number')

Result:
18CSC207J
AIM :

PSEUDOCODE:

18CSC207J
OUTPUT:

Which game do you like,

Press C - Cricket

H - Hokey: C

You are a Cricketer!


Program 3:
choice = input(f'Which game do you like, Press\nC - Cricket\nH - Hokey: ')
if choice == 'C':
print('You are a
Cricketer!') elif choice ==
'H':
print('You are a Hockey player!')
else:
print('You are not interested in Sports')

Result:
18CSC207J
AIM :

PSEUDOCODE:

18CSC207J
OUTPUT:

Aston

Audi

McLaren
Program 4:

cars =["Aston", "Audi", "McLaren"]

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

print("The factorial of", num, "is", calc_factorial(num))

Result:
18CSC207J
AIM:

PSEUDOCODE:

18CSC207J
OUTPUT:

3
Program 3:

def swap(x, y):

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

def withdraw(self, amount):


self.balance -= amount
return self.balance

def deposit(self, amount):


self.balance += amount
return self.balance

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

s = Student("SURYA PRAKASH", 101, 22)


print(getattr(s, 'name'))
setattr(s, "age", 23)
print(getattr(s, 'age'))
print(hasattr(s, 'id'))
delattr(s, 'age')

Result:
18CSC207J
AIM:

PSEUDOCODE:

18CSC207J
OUTPUT:

Enter Employee Name SURYA

PRAKASH Enter Employee age 19

Hello my name is SURYA

PRAKASH Iam 19 years old!


Program 3 :

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

name= input("Enter Employee Name")


age= input("Enter Employee age")

p1 = Person(name, age)
p1.myfunc()

Result:
18CSC207J
AIM:

PSEUDOCODE:

18CSC207J
OUTPUT 4 :

Area of Square: 25

Area of Triangle : 10.0


Program 4:

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=98) 8 event (x=-2,

y=23) 7 event (x=6,

y=1)

8 event (x=20, y=-1)

7 event (x=34,

y=98) 8 event (x=4,

y=-1)

18CSC207J
Program 2 :

from tkinter import *


import tkinter as tk

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)

def print_event(self, event):


position = "(x={}, y={})".format(event.x, event.y)
print(event.type, "event", position)

if name == " main ":


app = App()
app.mainloop()

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 :

from tkinter import *


import tkinter as tk
import tkinter as event

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 :

Symbol: g, Code: 71, Char: g

Symbol: f, Code: 70, Char: f

Symbol: j, Code: 74, Char: j

Symbol: t, Code: 84, Char: t

Symbol: f, Code: 70, Char: f

Symbol: j, Code: 74, Char: j

Symbol: Win_L, Code: 91, Char:

Symbol: Win_L, Code: 91, Char:

Symbol: Shift_L, Code: 16, Char:

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)

def print_type(self, event):


print(event.type)

def print_key(self, event):


args = event.keysym, event.keycode, event.char
print("Symbol: {}, Code: {}, Char:
{}".format(*args)) if name == " main ":
app = App()
app.mainloop()

Result:

18CSC207J
Ex. No.: 5 DECLARATIVE PROGRAMMING PARADIGM
Date :

AIM:

PSEUDOCODE:

18CSC207J
OUTPUT 1 :

(109, ‘SURYA PRAKASH', 19)

18CSC207J
Program 1 :

import sqlite3

con = sqlite3.connect('Students.db')
c=con.cursor()

c.execute('''CREATE TABLE student(roll_no INTEGER,name TEXT,age


INTEGER);''') c.execute('''INSERT INTO student VALUES(49,'Aman Bhai Patel',19)''')

con.commit()

for row in c.execute('''SELECT * FROM student'''):


print(row)

Result:

18CSC207J
AIM:

PSEUDOCODE:

18CSC207J
OUTPUT :

(‘SURYA PRAKASH', 'Job1')

('SURYA PRAKASH_a', 'Job2')

(‘SURYA PRAKASH_b', 'Job1')

(‘SURYA PRAKASH_c', 'Job2')

18CSC207J
Program:

import sqlite3

con = sqlite3.connect("file3.db")
c = con.cursor()

c.execute('''CREATE TABLE t1(id INTEGER,name


TEXT);''') c.execute('''CREATE TABLE t2(id INTEGER,job
TEXT);''')

c.execute('''INSERT INTO t1 VALUES(1,'Aman'),(2,'Aviraj'),(1,'Nithish'),(2,'Venkat');''')


c.execute('''INSERT INTO t2 VALUES(1,'Job1'),(2,'Job2');''')

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:

(1, 'SURYA PRAKASH')

(2, ‘SURYA PRAKASH_a')

(3, ‘SURYA PRAKASH_b')

Deleting an enrty : (3,SURYA PRAKASH_b)

Table is now:

(1, SURYA PRAKASH')

(2, SURYA PRAKASH_a')

Updating a name to full name:

Table is now:

(1, SURYA PRAKASH')

(2, SURYA PRAKASH_a')

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)

c.execute("CREATE TABLE datatable(ID INTEGER,Name TEXT);")

namelist = [(1,'Aman'),(2,'Aviraj'),(3,'Venkat')]
c.executemany("INSERT INTO datatable VALUES(?,?)",namelist)
con.commit()

print("\nInitial table: ")


printall()

print("\nDeleting an enrty : (3,Venkat)")


c.execute("DELETE FROM datatable WHERE Name =
'Venkat';") print("\nTable is now: ")
printall()

print("\nUpdating a name to full name:")


print("\nTable is now: ")
c.execute("UPDATE datatable SET Name='AMAN BHAI PATEL' WHERE
ID=1;") printall()

Result:

18CSC207J
18CSC207J
AIM:

PSEUDOCODE:

18CSC207J
OUTPUT:

Opened database

successfully Table created

successfully Opened

database successfully

Records created 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')

print ("Opened database successfully");


import sqlite3

conn = sqlite3.connect('test.db')
print ("Opened database successfully")

conn.execute('''CREATE TABLE COMPANY (ID INT PRIMARY KEY NOT


NULL, NAME TEXT NOT NULL,
AGE INT NOT NULL,
ADDRESS CHAR(50),
SALARY REAL);''')
print("Table created
successfully") conn.close()

import sqlite3

conn = sqlite3.connect('test.db')
print ("Opened database successfully")

conn.execute("INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY)


\ VALUES (1, 'Paul', 32, 'California', 20000.00 )");

conn.execute("INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY)


\ VALUES (2, 'Allen', 25, 'Texas', 15000.00 )");

conn.execute("INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY)


\ VALUES (3, 'Teddy', 23, 'Norway', 20000.00 )");

conn.execute("INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) \


VALUES (4, 'Mark', 25, 'Rich-Mond ', 65000.00 )");

conn.commit()
print ("Records created successfully")
conn.close()

import sqlite3

conn = sqlite3.connect('test.db')
print("Opened database successfully") 18CSC207J
Opened database

successfully Table created

successfully Records created

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

Operation done successfully

Opened database successfully

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

print("Operation done successfully")


conn.close()

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.execute("INSERT INTO COMPANY12345


(ID,NAME,AGE,ADDRESS,SALARY)\ VALUES (1, 'Paul', 32, 'California', 20000.00 )")

conn.execute("INSERT INTO COMPANY12345 (ID,NAME,AGE,ADDRESS,SALARY)


\ VALUES (2, 'Allen', 25, 'Texas', 15000.00 )")

conn.execute("INSERT INTO COMPANY12345 (ID,NAME,AGE,ADDRESS,SALARY)


\ VALUES (3, 'Teddy', 23, 'Norway', 20000.00 )")

conn.execute("INSERT INTO COMPANY12345 (ID,NAME,AGE,ADDRESS,SALARY)


\ VALUES (4, 'Mark', 25, 'Rich-Mond ', 65000.00 )")

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

print("Operation done successfully");


18CSC207J
conn.close()

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

Operation done successfully

Opened database successfully

Total number of rows deleted :

1 ID = 1

NAME = Paul

ADDRESS = California

SALARY = 25000.0

18CSC207J
import sqlite3

conn = sqlite3.connect('test.db')
print("Opened database successfully")

conn.execute("UPDATE COMPANY set SALARY = 25000.00 where ID =


1") conn.commit()
print ("Total number of rows updated :", conn.total_changes)

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

print("Operation done successfully")


conn.close()

import sqlite3

conn = sqlite3.connect('test.db')
print( "Opened database successfully")

conn.execute("DELETE from COMPANY where ID =


2;") conn.commit()
print ("Total number of rows deleted :", conn.total_changes)

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

print ("Operation done successfully");


conn.close()

18CSC207J
ID = 3

NAME = Teddy

ADDRESS =

Norway SALARY =

20000.0

ID = 4

NAME = Mark

ADDRESS = Rich-Mond

SALARY = 65000.0

Operation done successfully

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:

for num in range(10,20):


for i in range(2,num):
if num%i == 0:
j=num/i
print(num,i,j)
else:
print(num, "is a prime number")

Result:

You might also like