Saturday, February 24, 2018

Artificial Intelligence Python

Tags
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

Tags
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

Tags
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

Tags
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;