Professional Documents
Culture Documents
Advanced Programming Practice Lab: (Code 18CSC207J) B.Tech (CSE) - 2 Name
Advanced Programming Practice Lab: (Code 18CSC207J) B.Tech (CSE) - 2 Name
Advanced Programming Practice Lab: (Code 18CSC207J) B.Tech (CSE) - 2 Name
(Code 18CSC207J)
Name:
Registration no.:
Registration no.
Practical 1:- Write a Python program to draw square using Turtle Programming
Code :-
import turtle
skk = turtle.Turtle()
for i in range(4):
skk.forward(50)
skk.right(90)
turtle.done()
Output :-
Practical 2:- Write a python program to show basic tkinter program.
Code :-
from tkinter import *
win = Tk()
win.geometry("200x200")
w = Label(win, text="Hello, Welcome to python")
w.pack()
win.mainloop()
Output :-
LAB EXPERIMENT – 5
Declarative Programming
Code :-
import numpy as np
a = np.array([[1,2,3],[12,31,2]])
print("array 1",a)
a = np.array([[1,2,3],[9,21,5]])
print("array2",a)
a = np.array((1,3,2))
print("The tuple array",a)
Output :-
Practical 2:- To perform various functions to an array like adding, subtracting etc
Code :-
import numpy as np
a = np.array([[1,2,3],[12,31,2]])
print("array 1",a)
b = np.array([[1,5,8],[9,21,5]])
print("array2",b)
print("Add 1",a + 1)
print("sub 1",a - 1)
print("Mul 2", a*2)
print("divide 2", a/2)
print("Add 2 array", a + b)
print("subtract 2 array", a - b)
print("mutiply 2 array", a * b)
print("divide 2 array", a / b)
Output :-
LAB EXPERIMENT – 6
Imperative Programming
Code :-
a = int(input("Enter the number "))
t=a
s=0
for i in range(3):
d = t%10
s = s+ d**3
t=t/10
if s == a:
print("An Armstrong number")
else:
print("Not an armstrong number")
Output :-
Practical 2:- Find the number is prime or not.
Code :-
a = int(input("Enter the number "))
if a>1:
for i in range(2,a):
if a%i==0:
print("The number is not a prime number")
break
if i==(a -1):
print("The number is a prime number")
Output :-
LAB EXPERIMENT – 7
Parallel Programming
Code :-
from threading import *
def display() :
for i in range(3) :
print("Child Thread")
Thread_obj = Thread(target=display)
Thread_obj.start()
for i in range(3):
print('Main Thread')
Output :-
Practical 2:- Create Threads using class.
Code :-
from threading import Thread,current_thread
class AB(Thread):
def ren(self):
for i in range(7):
print("child")
a = AB()
a.start()
a.join()
print("Bye from",current_thread().getName())
Output :-
LAB EXPERIMENT – 8
Concurrent Programming
Code :-
import threading
import time
class AB(threading.Thread):
def run(self):
for i in range(6):
print("child")
a = AB()
a.start()
time.sleep(1)
print("Bye ")
Output :-
Code :-
double = lambda x : x*5
print (double(5))
Output :-
Code :-
from pyDatalog import pyDatalog
pyDatalog.create_terms('big,small,brown,black,grey,dark,X,Y,Z')
+big('bear')
+big('elephant')
+small('cat')
+brown('bear')
+black('cat')
+grey('elephant')
dark(X)<=black(X)
dark(X)<=brown(X)
print(dark(X))
print('The smallest animal')
print(small(X))
Output :-
Code :-
for i in range(1,6):
for j in range(1,6-i):
print(" ",end=" ")
for k in range(1,(2*i)):
print("*",end=" ")
print("\n")
Output :-
Output :-
LAB EXPERIMENT – 12
Network Programming
Code :-
import socket
import sys
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print("Socket successfully created")
except socket.error as err:
print ("Socket creation failed with error %s"%(err))
port = 80
Output :-
CODE:-
import socket
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
host = socket.gethostname()
port = 12345
s.connect((host, port))
print ( s.recv(1024) )
s.close() OUTPUT:
LAB EXPERIMENT – 13
Symbolic Programming
Code :-
import sympy as sym
x, y = sym.symbols('x y')
e = x+2*y
print(e)
Output :-
Output :-
LAB EXPERIMENT – 14
Automata Programming
Code :-
from automata.fa.dfa import DFA
dfa = DFA(
states={'q0','q1','q2','d'},
input_symbols ={'0','1'},
transitions={
'q0':{'0':'d','1':'q1'},
'q1':{'0':'q2','1':'q1'},
'q2':{'0':'q2','1':'q1'},
'd':{'0':'d','1':'d'}
},
initial_state='q0' ,
final_states={'q2'}
)
if(dfa.accepts_input("1000")):
print("Accepted")
else:
print("Rejected")
Output :-
PRACTICAL 2: WAP for a language that accepts all strings starting with 01
OR ending with 01
Q/E 0 1
→A B D
B E C
C* C C
D E D
E E F
F* E D
CODE:
OUTPUT:
Accepted
Lab 15: Graphical User Interface (GUI) Programming
Practical 1: Creating a form using tkinter
import tkinter
as tk from
tkinter import
* win = tk.Tk()
win.title("Registration Form") win.geometry('500x500')
bg = PhotoImage(file = 'C:\harshita\photo\sky.png') bg =
bg.subsample(5,5)
label1 = tk.Label( win, image = bg).place(x = 0,y = 0)