Professional Documents
Culture Documents
Board Rudra
roll Dave
no.:
11633201 th
Class: 12 science B
INDEX
SN TOPIC PAGE SIGNATUR
O. NO. E
PYTHON PROGRAMS
1 W.A.P that calculates and prints the
number of seconds in a year.
2 W.A.P that reads a date as an integer
in the format MMDDYYYY. The
program will call a function that
prints print out the date in the format
<Monthname> <day> < year>.
3 W.A.P that reads two times in
military format (0900,1730) and
prints the number of hours and
minutes between the two times.
4 W.A.P that creates a tuple storing
first 9 terms of Fibonacci Series.
5 Create a dictionary whose keys are
months names and whose values are
the number of days in the
corresponding months.
a. Ask the user to enter a month
name and use the dictionary to tell
them how many days are in the
month
b. Print out all of the keys in
alphabetical order
c. Print out all of the months with 31
days
d. Print out the pairs sorted by the
number of days in each month.
6 W.A.P to sort a dictionary's value
using Bubble sort and produce the
sorted values as a list.
7 W.A function that takes amount in
dollars and dollar to rupee
conversion price. It returns the
amount converted as per the user
selections. Create both void and non
void forms.
print(remove_letter(sentence, letter))
OUTPUT
16. W.A.P to display the size of a file in bytes and display the
number of lines in the file
file_path = r"D:\poem.txt"
file_obj = open(file_path)
print(file_obj.read())
file = open("D:\Poem.txt","r")
Counter = 0
Content = file.read()
CoList = Content.split("\n")
for i in CoList:
if i:
Counter += 1
import os
file_size = os.stat('D:/Poem.txt')
print("Size of file :", file_size.st_size, "bytes")
OUTPUT
Program17. W.A.P to display the content of the Emp table and then
create a binary file having Emp table records.
import pickle
emp={'Namita':25000,'Manya':30000,'Tanu':20000}
f1=open('emp.dat','wb')
pickle.dump(emp,f1)
f1.close()
f1=open('emp.dat','rb')
e=pickle.load(f1)
for x in e:
print(x)
f1.close()
OUTPUT
Program18. W.A.P that accepts student name, student no, class and
div and store the new entry in the tbl_Student table created in
Mysql
import mysql.connector
cnx = mysql.connector.connect(user='root', password='Baroda@01',
host='localhost',
database='student')
cursor=cnx.cursor()
sname = input("enter your full name :")
rno = input("enter your roll number :")
clss = input("enter your class :")
division = input("enter your division :")
query = "Insert into tbl_student(sname,rno,class,division) values('{}',{},
{},'{}')".format(sname,rno,clss,division)
cursor.execute(query)
cnx.commit()
19. W.A.P that displays a menu to the user as shown below:
a. Add New Record
b. Edit Existing Record.
If the user selects (a) User enters the data like Item name, price per
unit, and qty and inserts into the tbl_Item_Mst having columns like
ItemNo (P.K), ItemName varchar(80), Price float(6), Qty int(3).If
user selects (b) Edit the existing record and maintain the changed
record details in binary file along with the current date.
import mysql.connector
myconn=mysql.connector.connect(host="localhost",user="root",passwd
="aditya",database="project")
cur=myconn.cursor()
a="create table tbl_Item_Mst(ItemNo int(10) primary key, ItemName
varchar(80), Price float(6), Qty int(3))"
cur.execute(a)
myconn.commit()
print("""What do you want to do:
1)Add new record
2)Edit existing record""")
ans=int(input("Enter your choice:"))
if ans==1:
INo=int(input("Enter item number:"))
IN=input("Enter item name:")
PPU=float(input("Enter price per unit:"))
Q=int(input("Enter item quantity:"))
b="insert into tbl_Item_Mst values({},'{}',{},
{})".format(INo,IN,PPU,Q)
cur.execute(b)
myconn.commit()
else:
myfile=open("stalk.txt","w")
INo1=int(input("Enter item number:"))
IN1=input("Enter item name:")
PPU1=float(input("Enter price per unit:"))
Q1=int(input("Enter item quantity:"))
c="update tbl_Item_Mst set
ItemNo={},ItemName='{}',Price={},Qty={}".format(INo1,IN1,PPU1,Q
1)
myfile.close()
20. W.A.P that accepts city name from the user and then creates a
CSV file for the data that is stored in the tbl_City_Mst having
column (CityId, CityName). If the city is getting repeated display
the message 'City already exist' and terminate the program else, add
it to the table also update the CSV file with latest data from the
table.
import pickle
c={}
found=False
#SELECT * FROM myTable INTO OUTFILE
'C:\Users\DELL\Desktop\Data.csv' FIELDS ENCLOSED BY '"'
TERMINATED BY ';' ESCAPED BY '"' LINES TERMINATED BY
'\r\n';
CN=input("Enter the city name")
myfile=open("Data.txt","rb+")
try:
while True:
rpos=myfile.tell()
c=pickle.load(myfile)
if c['City name']==CN:
print("City already exist!!Can't enter")
found=True
else:
c['City name']=CN
myfile.seek(rpos)
pickle.dump(c,myfile)
except:
pass
Q-2 Insert following data into the above mentioned table: (NOTE:
in file write 5 insert statements):
insert into tbl_products values
(1,'Chai',1,1,'10boxesx20bags',18,39,0,10),
(2,'Chang',1,1,'24-12ozbottles',19,17,40,25),
(3,'Anissed syrup',1,1,'12-550mlbottles',10,13,70,25),
(4,'Chef antons cajun seasoning',1,2,'48-6ozjars',22,53,0,0),
(5,'Chef antons gumbo mix',2,2,'36boxes',21.35,0,0,0),
(6,'Grandma boysenberry',3,2,'12-8ozjars',25,120,0,25),
(7,'Bob organic Dried Pears',3,7,'12-1lbpkgs',30,15,0,25),
(8,'Northwoods Cranberry',3,2,'12-12ozjars',40,6,0,0),
(9,'Mishi Kobe',4,6,'18-500gpkgs',97,29,0,0),
(10,'Ikura',4,8,'12-200mljars',31,31,0,0),
(11,'Queso cabrales',5,4,'1kgpkg',21,22,30,30),
(12,'Queso Manchego',5,4,'10-500gpkgs',38,86,0,0),
(13,'Konbu',6,8,'2KgBox',6,24,0,5),
(14,'Tofu',6,7,'40-100gpkgs',23.25,35,0,0),
(15,'Genen',6,2,'24-250mlbottles',15.5,39,0,5);
OUTPUT