Академический Документы
Профессиональный Документы
Культура Документы
No.(2)
AIM: Write a program to check a number whether it is palindrome or not.
No.(3)
AIM: Write a program to calculate compound interest.
SOURCE p=float(input("Enter the principal amount : "))
CODE: r=float(input("Enter the rate of interest : "))
t=float(input("Enter the time in years : "))
x=(1+r/100)**t
CI= p*x-p
print("Compound interest is : ", round(CI,2))
EXPECTED
OUTPUT:
No.(4)
AIM: Write a program to display ASCII code of a character and vice versa.
No.(5)
AIM: Write a program to input a character and to print whether a given character is an
alphabet, digit or any other character.
SOURCE ch=input("Enter a character: ")
CODE: if ch.isalpha():
print(ch, "is an alphabet")
elif ch.isdigit():
print(ch, "is a digit")
elif ch.isalnum():
print(ch, "is alphabet and numeric")
else:
print(ch, "is a special symbol")
EXPECTED
OUTPUT:
No.(6)
AIM: Write a program to calculate the factorial of an integer using recursion.
No.(7)
AIM: Write a program to print fibonacci series using recursion.
No.(8)
AIM: Write a program for binary search.
No.(9)
AIM: Write a recursive python program to test if a string is palindrome or not.
No.(10)
AIM: Write a program to count the number of vowels present in a text file.
SOURCE CODE: fin=open("D:\\b.txt",'r')
str=fin.read( )
count=0
for i in str:
if i=='a' or i=='e' or i=='i' or i=='o' or i=='u':
count=count+1
print(count)
EXPECTED
OUTPUT:
No.(11)
AIM: Write a program to write those lines which have the character 'p' from one text file to
another text file.
SOURCE CODE: fin=open("D:\\b.txt","r")
fout=open("D:\\a.txt","a")
s=fin.readlines( )
for j in s:
if 'p' in j:
fout.write(j)
fin.close()
fout.close()
EXPECTED
OUTPUT:
No.(12)
No.(13)
AIM:
No.(14)
AIM: Write a program to generate random numbers between 1 to 6 and check whether a user
won a lottery or not.
SOURCE CODE: import random
n=random.randint(1,6)
guess=int(input("Enter a number between 1 to 6 :"))
if n==guess:
print("Congratulations, You won the lottery ")
else:
print("Sorry, Try again, The lucky number was : ", n)
EXPECTED
OUTPUT:
No.(15)
AIM: Write a program to plot a bar chart in python to display the result of a school for five
consecutive years.
No.(16)
AIM: Write a program in python to plot a graph for the function y = x2.
No.(17)
AIM: Write a program in python to plot a pie chart on consumption of water in daily life.
SOURCE CODE: import matplotlib.pyplot as pl
consumption=[5,30,50,3]
pl.pie(consumption, labels=['drink','bath','washing_clothes','Cooking'], autopct= '
%1.1f%% ' )
pl.show( )
EXPECTED
OUTPUT:
No.(18)
AIM: Write a program for linear search.
SOURCE CODE: L=eval(input("Enter the elements: "))
n=len(L)
item=eval(input("Enter the element that you want to search : "))
for i in range(n):
if L[i]==item:
print("Element found at the position :", i+1)
break
else:
print("Element not Found")
EXPECTED
OUTPUT:
No.(19)
AIM: Write a program for bubble sort.
No.(20)
AIM: Write a program to count number of consonants in the given string.
#____main___-
string="abcde"
length=len(string)
print(totalconsonant(string,length))
EXPECTED
OUTPUT:
No.(21)
No.(21)
AIM: Write a program to calculate a**b using iterative code.
No.(22)
AIM: Write a program to diplay the contents of file"a.txt".
No.(23)
AIM: Write a program in python to plot a pie chart on volunteering week collection.
No.(24)
AIM: Write a program for inserting an element in sorted array using traditional algorithm.
SOURCE CODE: def findpos(ar,item):
size=len(ar)
if item < ar[0]:
return 0
else:
pos=-1
for i in range(size-1):
if (ar[i]<=item and item<ar[i+1]):
pos=-1
break
if (pos==-1 and i<=size-1):
pos=size
return pos
def shift(ar,pos):
ar.append(None)
size=len(ar)
i=size-1
while i >= pos:
ar[i]=ar[i-1]
i=i-1
mylist=[10,20,30,40,50,60,70]
print("the list in sorted order is",mylist)
item=int(input("enter new element to be inserted :"))
position=findpos(mylist,item)
shift(mylist,position)
mylist[position]=item
print("the list after inserting",item,"is",mylist)
EXPECTED
OUTPUT:
No.(25)
AIM: Write a program in python insertion in sorted array using bisect module.
No.(26)
No.(27)
AIM: Write a program in python to calculate total amount to be paid including GST.
No.(28)
AIM: Write a proram in python for implementation of queue as a list.
No.(29)
AIM: Write a program in python for implementation of stack using list.
No.(30)
AIM: Write a program in python to implement queue operations.
def isempty(qu):
if qu==[]:
return True
else:
return False
def enqueue(qu,item):
qu.append(item)
if len(qu)==1:
front=rear=0
else:
rear=len(qu)-1
def dequeue(qu):
if isempty(qu):
return "underflow"
else:
item=qu.pop(0)
return item
def peek(qu):
if isempty(qu):
return "underflow"
else:
front=0
return qu[front]
def display(qu):
if isempty(qu):
print("queue empty!")
elif len(qu)==1:
print(qu[0],"<==front,rear")
else:
front=0
rear=len(qu)-1
for a in range(1,rear):
print(qu[a])
print(qu[rear],"<-rear")
## main ##
queue=[]
front=None
while True:
cls()
print("QUEUE OPERATIONS")
print("1.Enqueue")
print("2.Dequeue")
print("3.peek")
print("4.display")
print("5.exit")
ch=int(input("enter your choice(1...5):"))
if ch==1:
item=int(input("enter item:"))
enqueue(queue,item)
# input("press enter to continue")
elif ch==2:
item=dequeue(queue)
if item=="underflow":
print("underflow queue is empty")
else:
print("dequeue-ed item is empty!")
# input("press enter to continue...")
elif ch==3:
item=peek(queue)
if item=="underflow":
print("queue is empty")
else:
print("frontmost item is ",item)
# input("press enter to continue..")
elif ch==4:
display(queue)
# input("press enter to continue...")
elif ch==5:
break
else:
print("invalid choice")
EXPECTED
OUTPUT:
No.(31)
AIM: Write a program to find the most common phising email from a list of 10 emails saved
in a text file named email.txt .
SOURCE CODE: import collections
fin = open('D:\\email.txt','r')
a= fin.read()
d={ }
L=a.lower().split()
for word in L:
word = word.replace(".","")
word = word.replace(",","")
word = word.replace(":","")
word = word.replace("\"","")
word = word.replace("!","")
word = word.replace("&","")
word = word.replace("*","")
for k in L:
key=k
if key not in d:
count=L.count(key)
d[key]=count
n_print = int(input("How many most common words to print: "))
print("\nOK. The {} most common email are as follows\n".format(n_print))
word_counter = collections.Counter(d)
for word, count in word_counter.most_common(n_print):
print(word, ": ", count)
fin.close()
EXPECTED
OUTPUT:
No.(32)
AIM: Write a program to create a graphical calculator using tkinter library.
SOURCE CODE: from tkinter import *
def btnClick(number):
global operator
operator=operator+str(number)
strvar.set(operator)
def btnClear():
global operator
operator=''
strvar.set(operator)
def result():
global operator
res=str(eval(operator))
strvar.set(res)
root=Tk()
root.title("Calculator")
operator=''
strvar=StringVar()
ent=Entry(root,width=50,bd=5,font=('arial',10,"bold"),bg="powder
blue",textvariable=strvar,justify="right").grid(columnspan=4)
btn7=Button(root,text="7",padx=10,pady=10,font=('arial',10,"bold"),bg="powder
blue",command=lambda:btnClick(7)).grid(row=1,column=0)
btn8=Button(root,text="8",padx=10,pady=10,font=('arial',10,"bold"),bg="powder
blue",command=lambda:btnClick(8)).grid(row=1,column=1)
btn9=Button(root,text="9",padx=10,pady=10,font=('arial',10,"bold"),bg="powder
blue",command=lambda:btnClick(9)).grid(row=1,column=2)
btnPlus=Button(root,text="+",padx=10,pady=10,font=('arial',10,"bold"),bg="powder
blue",command=lambda:btnClick('+')).grid(row=1,column=3)
btn4=Button(root,text="4",padx=10,pady=10,font=('arial',10,"bold"),bg="powder
blue",command=lambda:btnClick(4)).grid(row=2,column=0)
btn5=Button(root,text="5",padx=10,pady=10,font=('arial',10,"bold"),bg="powder
blue",command=lambda:btnClick(5)).grid(row=2,column=1)
btn6=Button(root,text="6",padx=10,pady=10,font=('arial',10,"bold"),bg="powder
blue",command=lambda:btnClick(6)).grid(row=2,column=2)
btnMinus=Button(root,text="-",padx=10,pady=10,font=('arial',10,"bold"),bg="powder
blue",command=lambda:btnClick('-')).grid(row=2,column=3)
btn1=Button(root,text="1",padx=10,pady=10,font=('arial',10,"bold"),bg="powder
blue",command=lambda:btnClick(1)).grid(row=3,column=0)
btn2=Button(root,text="2",padx=10,pady=10,font=('arial',10,"bold"),bg="powder
blue",command=lambda:btnClick(2)).grid(row=3,column=1)
btn3=Button(root,text="3",padx=10,pady=10,font=('arial',10,"bold"),bg="powder
blue",command=lambda:btnClick(3)).grid(row=3,column=2)
btnMulti=Button(root,text="x",padx=10,pady=10,font=('arial',10,"bold"),bg="powder
blue",command=lambda:btnClick('*')).grid(row=3,column=3)
btn0=Button(root,text="0",padx=10,pady=10,font=('arial',10,"bold"),bg="powder
blue",command=lambda:btnClick(0)).grid(row=4,column=0)
btnClear=Button(root,text="C",padx=10,pady=10,font=('arial',10,"bold"),bg="powder
blue",command=btnClear).grid(row=4,column=1)
btnEqual=Button(root,text="=",command=result,padx=10,pady=10,font=('arial',10,"bol
d"),bg="powder blue").grid(row=4,column=2)
btnDivide=Button(root,text="/",padx=10,pady=10,font=('arial',10,"bold"),bg="powder
blue",command=lambda:btnClick('/')).grid(row=4,column=3)
Label(root,text="By:
ARUN.K.S",font=('COOPBAL',10,'italic'),fg='white',bg='black').grid(row=5,columnsp
an=4)
root.mainloop( )
EXPECTED
OUTPUT:
No.(33)
AIM: Write a program to open a webpage using urllib library.
SOURCE CODE: import urllib.request
data = urllib.request.urlopen('https://pythonschoolkvs.wordpress.com/')
print(data.read())
EXPECTED
OUTPUT:
No.(34)
AIM: Write a program to calculate EMI for a loan using numpy.
SOURCE CODE: import numpy as np
interest_rate= float(input("Enter the interest rate : "))
monthly_rate = (interest_rate)/ (12*100)
years= float(input("Enter the total years : "))
number_month = years * 12
loan_amount= float(input("Enter the loan amount : "))
emi = abs(np.pmt(monthly_rate, number_month, loan_amount))
print("Your EMI will be Rs. ", round(emi, 2))
EXPECTED
OUTPUT:
(2) ping: The ping command to test the availability of a networking device on a network.
If we receive a reply then the device is working OK, if we don’t then the device is faulty,
disconnected, switched off, incorrectly configured.
Syntax: ping IP address
Example: ping 162.215.252.78 (the website: http://www.cbseacademic.nic.in/)
(3) ipconfig : Displays all current TCP/IP network configuration values and refresh Dynamic Host
Configuration Protocol and Domain Name System settings.
Syntax: ipconfig
Example: ipconfig cbseacademic.nic.in
(4) nslookup : The nslookup (which stands for name server lookup) command is a network utility
program used to obtain information about internet servers. It finds name server information for
domains by querying the Domain Name System.
Syntax: nslookup domainname
Example: nslookup
(5) whois : The ‘whois’ command is a simple command-line utility that allows we to easily get
information about a registered domain. It automatically connect to the right WHOIS server,
according to the top-level domain name, and retrieve the WHOIS record of the domain. It supports
both generic domains and country code domains. Note: We need to use this command along with
‘nslookup’ command.
Syntax: nslookup
>whois domainname
Example: nslookup
>whois amazon.in
(6) speed-test: To test the internet speed using command prompt, firstly we need to install the
following using pip command.
C:\>pip install speedtest-cli
After successfully installation of above, run the following command.
speedtest-cli
UNIT – III: DATA MANAGEMENT
Topic: Usage of MySQL, Python MySQL Connectivity and Django based Web application
No.(35)
AIM: To find a min, max, sum and average of the marks in a student marks table.
TABLE USED:
No.(36)
AIM: To find the total number of customers from each country in the table using group by.
TABLE USED:
No.(37)
AIM: To write a SQL query to display (student ID,marks) from student table in descending
order of the marks.
TABLE USED:
MYSQL select student_id,marks from student group by marks desc;
QUERY:
OUTPUT:
No.(38)
C. Write a program in python to insert into tables(getting input from the user).
No.(39)
AIM: To write a Django based web server to parse a user request (POST), and write it to a CSV
file.
PROGRAM
:
STEP1: First a ‘demo’ folder is created with path- ‘C:\Demo’. Then the following commands
given in Windows command prompt.
STEP5: we need to import our application manually inside project ‘settings.py’by manually
typing ‘webapp’ inside Application Definitions.
STEP6: Now we open webapp/views.py and put below code init
STEP7: Now we need to map this view to a URL. So, we create a new python file “urls.py”
inside our ‘webapp’. In webapp/urls.py include the following code:
STEP8: Open ‘myproject/urls.py’ file and write the below code to point the root URL conf at
the webapp.urls module