Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Submitted by:
2020 and has been carried out under my direct supervision and
guidance.
submitted for any other examination and does not form a part of any
Signature of Principal
Moreover, the developer always feels the need, the help and good
wishes of the people near you, who have considerable experience and
idea.
Practical – I
Code :
length=len(string)
mid=length/2
rev=-1
for a in range(mid) :
if string[a]==string[rev] :
a += 1
rev -= 1
else :
break
else :
print(string,”is a palindrome”)
Practical – II
Code :
def arCalc(x,y) :
Output :
Sample run –
Enter number 1 : 13
Enter number 2 : 7
Practical – III
To generate a random integer number in range 15 to 35.
Code :
>>> print(random.randint(15,35))
Output :
Code :
myfile=open(r’E:\poem.txt’,”r”)
str=myfile.read()
size=len(str)
print(size,“bytes”)
Output :
Code :
fileout=open(“Student1.txt”,”w”)
for i in range(5) :
fileout.write(name)
fileout.write(‘\n’)
fileout.close()
Output :
Sample Run -
>>> Enter name of a student : Java
Java
Jivin
Jonathan
Jagjeet
Javed
Practical – VI
Code ;
def fact(n) :
if n < 2 :
return 1
return n* fact(n-1)
n=int(input(“Enter a number(>0):”))
print(“Factorial of”,n,“is”,fact(n))
Output ;
Sample Run –
Factorial of 4 is 24
Factorial of 5 is 120
Practical – VII
def fib(n) :
if n == 1 :
return 0
elif n == 2 :
return 1
else :
for i in range(1,n+1) :
print(fib(i),end=’,’)
print(“…”)
Output :
0, 1, 2, 3, 5, 8, 13, …
Practical – VIII
Code :
import matplotlib.pyplot as plt; plt.rcdefaults()
import numpy as np
import matplotlib.pyplot as plt
plt.show()
Output :
Practical – IX
Code :
import matplotlib.pyplot as plt
# Data to plot
labels = 'Python', 'C++', 'Ruby', 'Java'
sizes = [215, 130, 245, 210]
colors = ['gold', 'yellowgreen', 'lightcoral',
'lightskyblue']
explode = (0.1, 0, 0, 0) # explode 1st slice
# Plot
plt.pie(sizes, explode=explode, labels=labels,
colors=colors,
autopct='%1.1f%%', shadow=True, startangle=140)
plt.axis('equal')
plt.show()
Output :
Practical – X
Code :
import matplotlib.pyplot as plt
# line 1 points
x1 = [1,2,3]
y1 = [2,4,1]
# line 2 points
x2 = [1,2,3]
y2 = [4,1,3]
plt.xlabel('x - axis')
plt.ylabel('y - axis')
plt.legend()
plt.show()
Output :
Practical – XI
Program which depicts push & pop operation in stack.
Code :
stack.append("Ram")
stack.append("Iqbal")
print(stack)
print(stack.pop())
print(stack)
print(stack.pop())
print(stack)
Output :
Code :
print(queue)
queue.append("Akbar")
print(queue)
queue.append("Birbal")
print(queue)
print(queue.popleft())
print(queue.popleft())
print(queue)
Output :
deque(['Ram', 'Tarun', 'Asif', 'John'])
deque(['Ram', 'Tarun', 'Asif', 'John', 'Akbar'])
deque(['Ram', 'Tarun', 'Asif', 'John', 'Akbar', 'Birbal'])
Ram
Tarun
deque(['Asif', 'John', 'Akbar', 'Birbal'])
Practical – XIII
Code :
def binarySearch (arr, l, r, x):
if r >= l:
mid = l + (r – l)/2
if arr[mid] == x:
return mid
else:
else:
return -1
arr = [ 2, 3, 4, 10, 40 ]
x = 10
if result != -1:
else:
Output :
Practical – XIV
Code :
Mycon=sqltor.connect(host=”localhost”,user=”learner”,passwd=
”fast”,database=”test”)
if mycon.is_connected()==False :
cursor=mycon.cursor()
cursor.execute(“select*from student”)
data=cursor.fetchmany(3)
count=cursor.rowcount
print(row)
mycon.close()
Output :
(101,’Ruhani’, Decimal(‘76.80’),’A’,’A’,”Pending”)
(102,’George’, Decimal(‘71.20’),’B’,’A’,”Submitted”)
(103,’Simran’, Decimal(’81.20’),’A’,’B’,”Evaluated”)
Practical – XV
def reverse(string):
if len(string) == 0:
return
temp = string[0]
reverse(string[1:])
print(temp, end='')
reverse(string)
Output :
Code :
# Python Program to Calculate Cube of a Number
def cube(num):
return num * num * num
cub = cube(number)
Output :
Practical – XVII
Code :
def gcd(a,b):
if (a == 0):
return b
if (b == 0):
return a
if (a == b):
return a
if (a > b):
return gcd(a-b, b)
return gcd(a, b-a)
a = 98
b = 56
if(gcd(a, b)):
print('GCD of', a, 'and', b, 'is', gcd(a, b))
else:
print('not found')
Output :
GCD of 98 and 56 is 14
Practical – XVIII
Program that inpuits an integer 0-999 and then prints if the integer
entered is a 1/2/3 digit number.
Code:
num=int(input(“Enter a number(0..999):”))
if num < 0 :
else :
Output :
Sample run –
Practical – XIX
Practical – XX
Queries on given table.
• Display names and drink codes of those drinks that have more than 120
calories.
Code :
select DNAME<DRINKCODE
from SOFTDRINK
where CALORIES > 120 ;
• Display drink codes, names and calories of all drinks in descending order of
calories.
Code :
select DRINKCODE , DNAME,CALORIES
from SOFTDRINK
order by CALORIES desc ;
• Display names and prices of drinks that have price in the range 12 to 18.
Code :
select DNAME,PRICE
from SOFTDRINK
where PRICE BETWEEN 12 AND 18 ;
• Increase the price of all drinks in the given table by 10 %
Code :
UPDATE SOFTDRINK
set PRICE = PRICE + 0.10 * PRICE ;
Practical – XXI
Queries on given table.