Saturday, February 24, 2018

Artificial Intelligence Python

2.
Write a program to find the sum of all numbers stored in a list.
Code:
 
list=map(int,input("Enter List : ").strip().split());
s=0;
for j in list:
    s=s+j;
print("Sum is : ",s);

Output: 
 


 3.
Write a program to find factorial
of a number.
Code:
fact=1;
n=int(input("Enter Number : "));
for j in range(2,n+1):
    fact=fact*j;
print("Factorial is : ",fact);
 
Output:
 
 
 4.
Write a program to display formatted text calendar and entire calendar for a year
 
Code :
import calendar;
year=int(input("Enter Year"));
for month in range(1,13):
    print(calendar.month(year,month));
 
Output:
 
 
7.
Code:
celsius=int(input("Enter Temperatue in Celsius "))
f=celsius*1.8+32;
print('Temperatue in Farenheit is : ',f);
 
Output:
 
 

Wednesday, February 21, 2018

Program Classes and Objects

Write a program by creating objects to display student information


Code:

class Student:
    def __init__(self,name,c,rollno,phone,address):
        self.name=name
        self.c=c
        self.rollno=rollno
        self.phone=phone
        self.address=address

    def display(self):
        print('Name : ',self.name)
        print('Class : ',self.c)
        print('Roll No : ',self.rollno)
        print('Phone : ',self.phone)
        print('Address : ',self.address)
        print()


def main():
    john=Student('John','D3CSEA1',1507567,9023074222,'Ludhiana')
    john.display()
    print('********************','\n')
    jennie=Student('Jennie','D3CSEA2',1507542,8725053420,'Patiala')
    jennie.display()


main()

Output:
 


Tuesday, February 20, 2018

Best First Search AI

Code :

alist={
    'A':['B','C','D'],
    'B':['H'],
    'C':['G','F'],
    'D':['E','P'],
    'E':[],
    'F':[],
    'G':[],
    'H':['J','I'],
    'I':['M','L','K'],
    'J':[],
    'K':[],
    'L':[],
    'M':[],
    'P':[]

}

hfun={
    'A':0,
    'B':5,
    'C':6,
    'D':3,
    'E':8,
    'F':12,
    'G':14,
    'H':7,
    'I':5,
    'J':6,
    'K':1,
    'L':10,
    'M':2,
    'P':9}

def fsort(v):
    for j in range(0,len(v)):
        for i in range(0,len(v)-j-1):
            if(hfun[v[i]]>hfun[v[i+1]]):
                temp=v[i+1];
                v[i+1]=v[i];
                v[i]=temp;


oqueue=[];
cqueue=[];
goal='I'
oqueue.append('A');
success=Falsewhile len(oqueue)!=0:
    node= oqueue.pop(0)
    if node is goal:
        success=True        break    for i in alist[node]:
        oqueue.append(i)

    cqueue.append(node)

    fsort(oqueue)
    print(cqueue)

if(success):
    print("Found")
else:
    print("Not Found")

Output:
Please try at your IDE

Thursday, February 15, 2018

Programs ADS Lab

20.

CREATE PACKAGE emp_sal1 AS  
   PROCEDURE find_sal(empid emp7567.id%type);  
END emp_sal1;
 
Output:

 
 
 
CREATE OR REPLACE PACKAGE BODY emp_sal1 AS   
    
   PROCEDURE find_sal(empid emp7567.id%TYPE) IS  
   c_sal emp7567.salary%TYPE;  
   BEGIN  
      SELECT salary INTO c_sal  
      FROM emp7567  
      WHERE id = empid;  
      dbms_output.put_line('Salary: '|| c_sal);  
   END find_sal;  
END emp_sal1; 
 
 
DECLARE  
   empid emp7567.id%type :=1507567;  
BEGIN  
   emp_sal1.find_sal(empid);  
END;   



21.

Code:

declare
empid emp7567.id%type := &id;
row emp7567%rowtype;
invalid exception;
begin
if empid<=0 then
raise invalid;   --userdefined exception
end if;
select * into row   from emp7567 where id= empid;
dbms_output.put_line('Name ' || row.name);
EXCEPTION
   WHEN no_data_found THEN     --system defined
      dbms_output.put_line('No such Employee!');
   WHEN invalid THEN
      dbms_output.put_line('Error! Invalid Id');
END;






Saturday, January 27, 2018

Pl/SQl Programs ADS

16.
declare
cursor cursor is select * from emp7567 order by salary desc;
id emp7567.id%type;
name emp7567.name%type;
salary emp7567.salary%type;
begin
open cursor;
loop
fetch cursor into id,name,salary;
dbms_output.put('Id: '||id||' ');
dbms_output.put('Name: '||name||' ');
dbms_output.put('Salary: '||salary||' ');
dbms_output.put_line(' ');
exit when(cursor%rowcount>5);
end loop;
close cursor;
end;

17.
declare
rows number;
begin

update emp7567
set
salary=salary+0.25*salary;

if sql%notfound then
dbms_output.put_line('No Row Updated');
else
rows:=sql%rowcount;
dbms_output.put_line(rows||' Rows Updated');
end if;


end;

18.

declare
cursor cursor is select * from emp7567;
id emp7567.id%type;
name emp7567.name%type;
salary emp7567.salary%type;
begin
open cursor;
loop
fetch cursor into id,name,salary;
dbms_output.put('Id: '||id||' ');
dbms_output.put('Name: '||name||' ');
dbms_output.put('Salary: '||salary||' ');
dbms_output.put_line(' ');
exit when(cursor%notfound);
end loop;
dbms_output.put_line(cursor%rowcount||' Results Found');
close cursor;
end;

19.

create trigger uppercase7567 before insert  or update on emp7567
for each row
when (New.id>0)
begin
:New.name:=UPPER(:new.name);
end;

20.