The file is a collection of records, if we want to store program output permanently under a computer harddisk then we can use file handling operation.
File handling provide multiple operations on a file
Python Provide a predefined method to manage file handling operation.
1 open():- using this method we can open the file for operation, if the file not exist then it will create the file.
f = open("filename",mode) # w for write ,r for read ,w+ for write|read,r+ for read|write,a for append, a+ append and read
2 write():- this method is used to write content into a file.
f.write(data)
code for write
f = open("student.txt","w")
f.write("student information")
f.close()
3 read()
File handling provide multiple operations on a file
Python Provide a predefined method to manage file handling operation.
1 open():- using this method we can open the file for operation, if the file not exist then it will create the file.
f = open("filename",mode) # w for write ,r for read ,w+ for write|read,r+ for read|write,a for append, a+ append and read
2 write():- this method is used to write content into a file.
f.write(data)
code for write
f = open("student.txt","w")
f.write("student information")
f.close()
3 read()
code for read
f = open("student.txt","r")
s=f.read()
print(s)
f.close()
..................................................................................................................
4 append file:-
code for append
s=f.read()
print(s)
f.close()
s = f.read()
print(s)..................................................................................................................
4 append file:-
code for append
f = open("student.txt","a")
s = input("write content")
f.write(s)
f.close()
Create Expenses System using File Handling Program:-
s = input("write content")
f.write(s)
f.close()
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
Create Expenses System using File Handling Program:-
import time
f = open("expenses.txt","w")
expenseby = input("Enter expense by")
grocerry = input("Enter grocerry details")
milk = input("Enter milk expenses")
rent = input("Enter rent expenses")
date = time.asctime(time.localtime(time.time()))
f.write("Today Expenses Details")
f.write("\n")
f.write("Grocerry:"+grocerry)
f.write("\n")
f.write("Milk:" +milk)
f.write("\n")
f.write("Rent:" +rent)
f.write("\n")
f.write("Date:" + date)
f.close()
Expenses System program to append mode:-
import time
f = open("expenses.txt","a")
expenseby = input("Enter expense by")
grocerry = input("Enter grocerry details")
milk = input("Enter milk expenses")
rent = input("Enter rent expenses")
date = time.asctime(time.localtime(time.time()))
f.write("-------------*------------")
f.write("Today Expenses Details by "+expenseby)
f.write("\n")
f.write("Grocerry:"+grocerry)
f.write("\n")
f.write("Milk:" +milk)
f.write("\n")
f.write("Rent:" +rent)
f.write("\n")
f.write("Date:" + date)
f.write("-------------*------------")
f.close()
Expenses System Write and Read using Single File?
import time
f = open("expenses.txt","w+")
expenseby = input("Enter expense by")
grocerry = input("Enter grocerry details")
milk = input("Enter milk expenses")
rent = input("Enter rent expenses")
date = time.asctime(time.localtime(time.time()))
f.write("-------------*------------")
f.write("Today Expenses Details by "+expenseby)
f.write("\n")
f.write("Grocerry:"+grocerry)
f.write("\n")
f.write("Milk:" +milk)
f.write("\n")
f.write("Rent:" +rent)
f.write("\n")
f.write("Date:" + date)
f.write("-------------*------------")
f.seek(0)
s = f.read()
print(s)
f.close()
Expenses System Example With Append Mode:-
import time
f = open("expenses.txt","a+")
expenseby = input("Enter expense by")
grocerry = input("Enter grocerry details")
milk = input("Enter milk expenses")
rent = input("Enter rent expenses")
date = time.asctime(time.localtime(time.time()))
f.write("-------------*------------")
f.write("Today Expenses Details by "+expenseby)
f.write("\n")
f.write("Grocerry:"+grocerry)
f.write("\n")
f.write("Milk:" +milk)
f.write("\n")
f.write("Rent:" +rent)
f.write("\n")
f.write("Date:" + date)
f.write("-------------*------------")
f.seek(0)
s = f.read()
print(s)
f.close()
Program of file handling using class and object:-
class FileOperation:
def createFile(self):
self.f = open("info.txt","a+")
def writeFile(self):
title = input("Enter title")
self.f.write("\n"+title)
desc = input("Write content")
self.f.write("\n"+desc)
def readFile(self):
self.f.seek(0) #it will reset cursor position to any index
res = self.f.read()
print(res)
self.f.close()
obj = FileOperation()
obj.createFile()
obj.writeFile()
obj.readFile()
def createFile(self):
self.f = open("info.txt","a+")
def writeFile(self):
title = input("Enter title")
self.f.write("\n"+title)
desc = input("Write content")
self.f.write("\n"+desc)
def readFile(self):
self.f.seek(0) #it will reset cursor position to any index
res = self.f.read()
print(res)
self.f.close()
obj = FileOperation()
obj.createFile()
obj.writeFile()
obj.readFile()
Program to create a resume using file handling?
f = open("resume1.doc","w+")
f.write("Objective")
f.write("\n I am seeking job and i will work with full honesty and learn new skills")
f.write("\n Qualification")
f.write("\n I have completed BTECH from IPS college Indore")
f.write("\n Academic Qualification")
f.write("\n 10th 80% \n 12th 90% ")
f.close()
Program to calculate SI using P, R, and T?
p = float(input("enter amount"))
r = float(input("enter rate"))
t = float(input("enter time"))
si = (p*r*t)/100
f = open("sicalc.txt","w")
f.write("Amount is "+str(p)+ "\n Rate is "+str(r)+ "\n Time is "+str(t))
f.write("Result is "+str(si))
f.close()
Program to calculate Simple Interest using Write and Read Mode?
p = float(input("enter amount"))
r = float(input("enter rate"))
t = float(input("enter time"))
si = (p*r*t)/100
f = open("sicalc.txt","w+")
f.write("Amount is "+str(p)+ "\n Rate is "+str(r)+ "\n Time is "+str(t))
f.write("Result is "+str(si))
f.seek(0)
data = f.read()
print(data)
f.close()
Program to calculate Simple Interest using Append and Read Mode?
p = float(input("enter amount"))
r = float(input("enter rate"))
t = float(input("enter time"))
si = (p*r*t)/100
f = open("sicalc.txt","a+")
f.write("Amount is "+str(p)+ "\n Rate is "+str(r)+ "\n Time is "+str(t))
f.write("Result is "+str(si))
f.seek(0)
data = f.read()
print(data)
f.close()
Assignment:-
1) WAP to perform the addition of two numbers and write the output of addition under file?
2) WAP to create complete biodata for a marriage proposal?
3) WAP to create horoscope software?
Create Expenses System.
import time
f = open("expenses.txt","a+")
expenseby = input("Enter expense by")
grocerry = input("Enter grocerry details")
milk = input("Enter milk expenses")
rent = input("Enter rent expenses")
date = time.asctime(time.localtime(time.time()))
f.write("\n Today Expenses Details")
f.write("\n")
f.write("Name:"+expenseby)
f.write("\n")
f.write("Grocerry:"+grocerry)
f.write("\n")
f.write("Milk:" +milk)
f.write("\n")
f.write("Rent:" +rent)
f.write("\n")
f.write("Date:" + date)
f.seek(0)
data = f.readlines()
s=0
for d in data:
if d[0]=='G' or d[0]=='R' or d[0] == 'M':
s = s + int(d[d.find(':')+1:])
print("Total Expenses is ",s)
f.close()
What is Data Processing?
It is used to process the data of an external drive under an application using multiple file formats.
Python provides multiple modules to read data from excel, CSV, word, pdf, image, and video files.
1) Read and write data from excel file using XLRD MODULE
Python provide xlrd modue.
pip install xlrd
.xsl, .xslx
Code to read data from excel file
import xlrd
f = xlrd.open_workbook("d://book1.xls")
sheet = f.sheet_by_index(0)
#s = sheet.cell_value(0,0)
#print(s)
r = sheet.nrows
c = sheet.ncols
print("row",r,"col",c)
for i in range(0,r):
for j in range(0,c):
print(sheet.cell_value(i,j),end=' ')
print()
How to write data on excel file:-
import xlwt
from xlwt import Workbook
# Workbook is created
wb = Workbook()
# add_sheet is used to create sheet.
sheet1 = wb.add_sheet('sheet1')
nrow=3
ncol=2
for i in range(0,nrow):
for j in range(0,ncol):
sheet1.write(i, j, input("Enter data for cell {0}{1}".format(i,j)))
wb.save('d://book3.xls')
2) READ DATA In FILE using openpyxl module
import openpyxl
dataframe = openpyxl.load_workbook("d://book1.xlsx")
dataframe1 = dataframe.active
print(dataframe1.max_row)
print(dataframe1.max_column)
for row in range(0, dataframe1.max_row):
for col in dataframe1.iter_cols(1, dataframe1.max_column):
print(col[row].value,end=' ')
print()
.............................................................................................................................................................
.............................................................................................................................................................
Write Data on Excel File?
# import openpyxl module
import openpyxl
wb = openpyxl.Workbook()
sheet = wb.active
c1 = sheet.cell(row = 1, column = 1)
c1.value = "ANKIT"
c2 = sheet.cell(row= 1 , column = 2)
c2.value = "RAI"
c3 = sheet['A2']
c3.value = "RAHUL"
c4 = sheet['B2']
c4.value = "RAI"
wb.save("d://demo123.xlsx")
...............................................................................................................................
Write Multiple Data on Exel file:-
# import openpyxl module
import openpyxl
wb = openpyxl.Workbook()
sheet = wb.active
nrow=int(input("Enter row"))
ncol=int(input("Enter col"))
for i in range(1,nrow+1):
for j in range(1,ncol+1):
c1 = sheet.cell(row = i, column = j)
c1.value = input("Enter data for row "+str(i) + "col " + str(j))
wb.save("d://demo123.xlsx")
# WAP to perform the addition of two numbers and write the output of addition under file?
ReplyDeletea=int(input("enter first number"))
b=int(input("enter second number"))
s=a+b
f=open("addition.txt","w+")
f.write("a is"+str(a)+"\n b is"+str(b)+"\nsum is"+str(s))
f.close()
#wap to create bio data for marriag
ReplyDeletef = open("biodata.doc","w+")
f.write("abc")
f.write("\n In my family five member my parents and two sibling\n")
f.write("\n i have complteted mbbs\n")
f.write("\n age is 25\n")
f.write("\n dob is 4-5-1995")
f.write("\n hindu\n")
f.write("\n working in govt college as a professor\n")
f.write("\n i can speak hindi and english both\n")
f.write("\n hindu\n")
f.close()
#Program to create a resume using file handling?
ReplyDeletef = open("resume.doc","w+")
f.write("Objective")
f.write("\n I am seeking a job, where I can use my exp and skills for the growth of company")
f.write("\n Qualification")
f.write("\n I have completed B.E from Electronics and Communcation branch")
f.write("\n Academic Qualification")
f.write("\n 10th = 76% and 12th = 68%")
f.seek(0)
s=f.read()
print(s)
f.close()
#Program to calculate Simple Interest using Write and Read Mode?
ReplyDeletef=open("SI.txt","w+")
p = int(input("Enter principal Amount"))
r= int(input("Enter rate of interest = "))
t = int(input("Enter time period = "))
si = (p*r*t)/100
f.write(str(si))
f.seek(0)
q=f.read()
print("SI for ",p,r,t,"= ",q)
f.close()
# Addition of two number
ReplyDeletea = int(input("Enter first number"))
b = int(input("Enter second number"))
ad =a +b
f= open("Addition.txt","a+")
f.write("\n"+str(ad))
f.seek(0)
q=f.read()
print(str(a)+"+"+str(b)+"=" +str(ad))
print(q)
f.close()
# Biodata
ReplyDeletef= open("Biodata.doc","w+")
f.write("Name - Parag")
f.write("\n Occupation - Financial Advisor")
f.write("\n DOB -26/11/1992")
f.write("\n Manglik- No")
f.write("\n Address- Indore")
f.seek(0)
q = f.read()
print(q)
f.close()
# Horoscope
ReplyDeletef=open("Horoscope.txt","w+")
f.write("Aries- It is beat to not loosen the pursestrings till you become financially stable")
f.write("\n Taurus - Money will come in as word about your skills gets around. taking break to go on a vaction is indicated")
f.write("\n Cancer- Purchasing an expensive item can prove heavy on the pocket.")
f.write("\n Leo- Agood understanding with spouse will bring happiness into your life.")
f.write("\n Virgo- Homemakers will manage to reset the house")
f.write("\n Libra- Paperwork regarding property is set to get completed soon")
f.write("\n Scorpio - A professional advice taken from someone may not prove hundred percent correct")
f.write("\n Sagittarius - Good preparation will find students performing well in a exam or competition")
f.write("\n Capricon - You want to help out an elder by showing all your concern, but you can feel disappointed when it is not reciprocated.")
f.write("\n Aquarius - You will managae to find time today to spend with family")
f.write("\n Pisces - Family get-together will give you a chance to mingle with cousins and other relatives")
f.seek(0)
q= f.read()
print(q)
f.close()
#AKASH PATEL
ReplyDeleteADDITION OF TWO NUMBERS:----
a=int(input("enter first number"))
b=int(input("enter second number"))
sum=a+b
f=open("addition.txt","w+")
f.write("a is"+str(a)+"\n b is"+str(b)+"\n sum is"+str(sum))
f.close()
#Akash patel
ReplyDeletef= open("Biodata.doc","w+")
f.write("Name - Akash Patel ")
f.write("\n Job- Cloud Engineer ")
f.write("\n DOB -14/07/1998 ")
f.write("\n Manglik- No")
f.write("\n Address- Khargone ")
f. write("\n Zodiac Sign-pisces")
Bdata= f.read()
print(Bdata)
f.close()
WAP to create complete expenses sheet?
ReplyDeleteimport time
while True:
o = input("\n Press w to write \n r to read \n e to exit")
if o=='w' or o=='W':
f = open("expenses.txt","a")
expenseby = input("Enter expense by")
grocerry = input("Enter grocerry details")
milk = input("Enter milk expenses")
rent = input("Enter rent expenses")
date = time.asctime(time.localtime(time.time()))
f.write("\n Today Expenses Details")
f.write("\n Expenses By " + expenseby)
f.write("\n")
f.write("Grocerry:"+grocerry)
f.write("\n")
f.write("Milk:" +milk)
f.write("\n")
f.write("Rent:" +rent)
f.write("\n")
f.write("Date:" + date)
f.close()
elif o=='r' or o=='R':
f = open("expenses.txt","r")
f.seek(0)
data = f.read()
print(data)
elif o=='e' or o=='E':
break
x = open("biodata.txt","a")
ReplyDeleteDOB= input("Enter DOB")
name = input("Enter name")
caste = input("Enter caste")
job = input("Enter JOB")
gender=input("enter gender")
x.write("\n biodata Details")
x.write("\n date of birth " + DOB)
x.write("\n")
x.write("name:"+name)
x.write("\n")
x.write("caste:" +caste)
x.write("\n")
x.write("job:" +job)
x.write("\n")
x.write("gender:" + gender)
x.close()
x = open("biodata.txt","r")
x.seek(0)
data = x.read()
print(data)
#Program to create a resume using file handling?
ReplyDeletewhile True:
o = raw_input("\n Press w to write \n r to read \n e to exit")
if o=='w' or o=='W':
f=open("resume.txt","w+")
f.write("\n **************Resume**********\n")
Name = raw_input("\n Enter your Name \n")
f.write("\n Name --"+Name)
Email_Id = raw_input(" \n Enter your Email \n ")
f.write("\n Email --"+Email_Id+"\n")
Address = raw_input("\n Enter your address \n")
f.write("\n Address --"+Address)
career_objective = raw_input("\n Enter career objectives \n")
f.write("\n career objectives --"+career_objective)
f.write("\n ************Academic Credentials************\n")
PG= raw_input("\n Enter post graduation \n")
per=raw_input("your percentage = ")
f.write("\n post gradutaion --"+PG+"percentage --"+per+"% \n")
G= raw_input("\n Enter graduation \n")
per=raw_input("your percentage = ")
f.write(" \ngradutaion --"+G+"percentage --"+per+"% \n")
HS= raw_input("\n Enter Higher secondary \n")
per=raw_input("your percentage = ")
f.write("\n Higher secondary --"+HS+"percentage --"+per+"% \n")
Hsc= raw_input("\n Enter High school \n")
per=raw_input("your percentage = ")
f.write("\n high school --"+Hsc+"percentage --"+per+"% \n")
ITskill=raw_input("Enter your IT Skill --\n ")
f.write=("\n ITskill - "+ ITskill +"\n")
experienced=raw_input("Enter your experienced")
f.write=(experienced+" -- years experienced \n")
f.write("\n ************personal profile************\n")
fathername=raw_input("Enter father name = ")
f.write("\n Father Name --"+fathername+"\n")
mothername=raw_input("Enter mother name = ")
f.write("\n mother Name --"+mothername+"\n")
DOB=input("Enter your date of birth")
f.write("\n DOB -- "+DOB+"\n")
gender=raw_input("Enter your gender")
f.write("\n Gender --"+gender)
f.seek(0)
data = f.read()
print(data)
f.close()
elif o=='e' or o=='E':
break
#Create Expenses System using File Handling Program with read & write mode w+?
ReplyDeleteimport time
import os
while True:
o = raw_input("\n Press w to write \n r to read \n e to exit")
if o=='w' or o=='W':
f = open("expenses.txt","w+")
expenseby = raw_input("Enter expense by = ")
grocerry = int(input("Enter grocerry expense = "))
milk = int(input("Enter milk expenses = "))
rent = int(input("Enter rent expenses = "))
date = time.asctime(time.localtime(time.time()))
f.write("\n Today Expenses Details")
f.write("\n Expenses By = " + expenseby)
f.write("\n")
f.write("Grocerry: "+str(grocerry))
f.write("\n")
f.write("Milk: " +str(milk))
f.write("\n")
f.write("Rent: " +str(rent))
f.write("\n")
f.write("Date: " + date)
f.write("\n")
total=grocerry+milk+rent
f.write("Total expense = "+str(total))
f.seek(0)
data = f.read()
print(data)
f.close()
elif o=='e' or o=='E':
break
# WAP to create complete biodata for a marriage proposal?
ReplyDeletewhile True:
o = raw_input("\n Press w to write \n r to read \n e to exit")
if o=='w' or o=='W':
f=open("biodata.txt","w+")
f.write("\n ***********Biodata for Marriage**********\n")
Name = raw_input("Enter your Name --")
f.write("\n Name --"+Name+"\n")
DOB=raw_input("Enter your date of birth --")
f.write("\n date of birth --"+ DOB +"\n")
height=raw_input("Enter your Height --")
f.write("\n Height --"+height+"\n")
weight=raw_input("Enter your weight --")
f.write("\n weight --"+weight+"\n")
Education=raw_input("Enter your Education --")
f.write("\n Education --"+Education+"\n")
Profession=raw_input("Enter your Profession --")
f.write("\n Profession --"+Profession+"\n")
Hobbies=raw_input("Enter your Hobbies --")
f.write("\n Hobbies --"+Hobbies+"\n")
Religion=raw_input("Enter your Religion --")
f.write("\n Religion --"+Religion+"\n")
fathername=raw_input("Enter father name --")
f.write("\n Father Name --"+fathername+"\n")
mothername=raw_input("Enter mother name -- ")
f.write("\n mother Name --"+mothername+"\n")
Email_Id = raw_input("Enter your Email --")
f.write("\n Email_Id --"+Email_Id+"\n")
Address = raw_input("Enter your address --")
f.write("\n Address --"+Address+"\n")
f.seek(0)
data = f.read()
print(data)
f.close()
elif o=='e' or o=='E':
break
SACHIN KUMAR GAUTAM
ReplyDelete#) WAP to create complete biodata for a marriage proposal user input?
import time
f=open("biodata.txt","a")
name=input("Enter the name")
dob=input("Enter the dob")
caste=input("Enter your caste")
horoscope=input("Enter the your horoscope")
education=input("complete education")
job=input("job info")
date=time.asctime(time.localtime(time.time()))
f.write("name:"+name)
f.write("\n")
f.write("dob:"+dob)
f.write("\n")
f.write("caste:"+caste)
f.write("\n")
f.write("horoscope:"+horoscope)
f.write("\n")
f.write("education:"+education)
f.write("\n")
f.write("job:"+job)
f.write("\n")
f.close()
# WAP to perform the addition of two numbers and write the output of addition under file?
ReplyDeletewhile True:
o = raw_input("\n Press w to write \n r to read \n e to exit")
if o=='w' or o=='W':
x=int(input("Enter first number = "))
y=int(input("Enter second number ="))
z=x+y
f=open("addition.txt","w+")
f.write("x is"+str(x)+"\n y is"+str(y)+"\n sum is"+str(z))
f.seek(0)
data = f.read()
print(data)
f.close()
elif o=='e' or o=='E':
break
# WAP to create complete biodata for a marriage proposal
ReplyDelete# Ankit Saxena
bd=open("Marrige Bio-Data","a")
print("-----Bio Daata (Enter You Details)-----")
date = time.asctime(time.localtime(time.time()))
name=input("Enter Your Name: ")
father =input("Father's Name: ")
mother=input("Mother's Name: ")
dob=input("Date of Birth: ")
place=input("Place of Birth: ")
mobile=input("Mobile No.: ")
address=input("Address: ")
cast=input("Cast: ")
gotra=input("Gotra: ")
language=input("Language: ")
height=input("Hight: ")
qualification=input("Qualification: ")
occupation=input("Occupation: ")
hobbies=input("Hobbies: ")
bd.write("Date: " + date)
bd.write("Name: " + name)
bd.write("\n")
bd.write("Father: " + father)
bd.write("\n")
bd.write("Mother: " + mother)
bd.write("\n")
bd.write("Date of Birth: " + dob)
bd.write("\n")
bd.write("Place: " + place)
bd.write("\n")
bd.write("Mobile No.: " + mobile)
bd.write("\n")
bd.write("Address: " + address)
bd.write("\n")
bd.write("Cast: " + cast)
bd.write("\n")
bd.write("Gotra: " + gotra)
bd.write("\n")
bd.write("Language: " + language)
bd.write("\n")
bd.write("Height: " + height)
bd.write("\n")
bd.write("Occupation: " + occupation)
bd.write("\n")
bd.write("Hobbies: " + hobbies)
print("---- details has been completed ----")
print("\n")
bd.close()
# WAP to create horoscope software
ReplyDelete# Ankit Saxena
while True:
option=input("Press to\n w to Write \n r to Read \n e to Exit \n Enter Your Choice: ")
if option=='w' or option=='W':
hs = open("horoscope.txt","a")
Aries=input("Enter Aries Horoscope Details: ")
Taurus=input("Enter Taurus Horoscope Details: ")
Gemini=input("Enter Gemini Horoscope Details: ")
Cancer=input("Enter Cancer Horoscope Details: ")
Leo=input("Enter Leo Horoscope Details: ")
Virgo=input("Enter Virgo Horoscope Details: ")
Libra=input("Enter Libra Horoscope Details:")
Scorpio=input("Enter Scorpio Horoscope Details: ")
Sagittarius=input("Enter Sagittarius Horoscope Details: ")
Capricorn=input("Enter Capricorn Horoscope Details: ")
Aquarius=input("Enter Aquarius Horoscope Details: ")
Pisces=input("Enter Pisces Horoscope Details: ")
hs.write("Aries:-" + Aries)
hs.write("\n")
hs.write("Taurus:-" + Taurus)
hs.write("\n")
hs.write("Gemini:-" + Gemini)
hs.write("\n")
hs.write("Cancer:-" + Cancer)
hs.write("\n")
hs.write("Leo:-" + Leo)
hs.write("\n")
hs.write("Virgo:-" + Virgo)
hs.write("\n")
hs.write("Libra:-" + Libra)
hs.write("\n")
hs.write("Scorpio:-" + Scorpio)
hs.write("\n")
hs.write("Sagittarius:-" + Sagittarius)
hs.write("\n")
hs.write("Capricorn:-" + Capricorn)
hs.write("\n")
hs.write("Aquarius:-" + Aquarius)
hs.write("\n")
hs.write("Pisces:-" + Pisces)
hs.close()
elif option=='r' or option=='R':
hs = open("horoscope.txt","r")
data = hs.read()
print(data)
elif option=='e' or option=='E':
break
f=open("Horoscope.txt","w+")
ReplyDeletef.write("Aries - If you are aiming to marry soon, you can start making preparations today. However, before you take the final decision, it would be better to look at both sides of the coin, advises Ganesha." )
f.write("\n Taurus - This day appears to be earmarked for a long shopping spree. Ganesha sees you doing the rounds of malls, markets, dollar stores and bargain counters." )
f.write("\n Cancer - A string of domestic responsibilities awaits you; today, you are about to realise that it is a long, long string.")
f.write("\n Leo - Nothing will overshadow your love for your kids today, and they will be the number one priority for you..")
f.write("\n Virgo - You will begin your journey on the long, hard road to success, predicts Ganesha." )
f.write("\n Libra - Today promises a definite sense of pride and joy from children who bring home glory, says Ganesha.")
f.write("\n Scorpio - In all probability, your mood is extremely hawkish today. Your belligerence may even put off Lady Luck for the time being.")
f.write("\n Sagittarius - Your business is all set to expand with you making the most of your overseas contacts.")
f.write("\n Capricon - You want to help out an elder by showing all your concern, but you can feel disappointed when it is not reciprocated.")
f.write("\n Aquarius - Success never comes easy, but in your case, it will make an exception, says Ganesha.")
f.write("\n Pisces - Family get-together will give you a chance to mingle with cousins and other relatives")
a= input(" today horosocope of ")
a_dict={}
a_file=open("Horoscope.txt",'r')
for line in a_file:
key,value=line.split(' - ')
a_dict[key]=value
if a in a_dict:
print(a_dict.get(a))
a_file.close()
#simple intrest
ReplyDeletep = float(input("enter amount"))
r = float(input("enter rate"))
t = float(input("enter time"))
si = (p*r*t)/100
f = open("sicalc.txt","a+")
f.write("Amount is "+str(p)+ "\n Rate is "+str(r)+ "\n Time is "+str(t))
f.write("Result is "+str(si))
f.seek(0)
data = f.read()
print(data)
f.close()
#biodata
ReplyDeletef= open("Biodata.doc","w+")
name= input("enter name")
school= input("enter school name")
education= input("enter education")
address= input("enter address")
manglik= input("manglik")
cast= input("enter cast")
dob= input("enter dob")
f.write("FULL Name - " +name)
f.write("\n SCHOOL - " +school)
f.write("\n EDUCATION - " +education)
f.write("\n ADDRESS - " +address)
f.write("\n MANGLIK- " +manglik)
f.write("\n CAST - " +cast)
f.write("\n Date of birth - " +dob)
f.seek(0)
q = f.read()
print(q)
f.close()
a=int(input("enter first no "))
ReplyDeleteb=int(input("enter second no"))
c=a+b
f=open("add2no.txt","w+")
f.write("1st no is"+str(a)+"\n2no is"+str(b)+"\n total is"+str(c))
f.seek(0)
d=f.read()
print(d)
f.close()
to perform the addition of two numbers and write the output of addition under file
ReplyDeletex=int(input("enter 1st number : "))
y=int(input("enter 2nd number : "))
z=x+y
a=open("addition.txt","w+")
a.write("x is"+str(x)+"\n y is"+str(y)+"\nsum is"+str(z))
a.close()
n=input("enter name")
ReplyDeletefn=input("enter father name")
mn=input("enter mother name")
dob=input("enter date of birth")
i=input("enter intrest areas")
ed=input("enter education")
o=input("enter ocupation")
f=open("bio.txt","w+")
f.write("Name:"+str(n)+"\nFather name:"+str(fn)+"\nMother name:"+str(mn)+"\nDate of birth"+str(dob)+"\nIntrest:"+str(i)+"\nEnter Education"+str(ed)+"\nEnter Occupation"+str(o))
d=f.read()
print(d)
f.close()
n=int(input("enter your birth month"))
ReplyDeletef=open("Horoscope.txt","w+")
if n==1:
f.write("Aries- It is beat to not loosen the pursestrings till you become financially stable")
elif n==2:
f.write("\n Taurus - Money will come in as word about your skills gets around. taking break to go on a vaction is indicated")
elif n==3:
f.write("\n Cancer- Purchasing an expensive item can prove heavy on the pocket.")
elif n==4:
f.write("\n Leo- Agood understanding with spouse will bring happiness into your life.")
elif n==5:
f.write("\n Virgo- Homemakers will manage to reset the house")
elif n==6:
f.write("\n Libra- Paperwork regarding property is set to get completed soon")
elif n==7:
f.write("\n Scorpio - A professional advice taken from someone may not prove hundred percent correct")
elif n==8:
f.write("\n Sagittarius - Good preparation will find students performing well in a exam or competition")
elif n==9:
f.write("\n Capricon - You want to help out an elder by showing all your concern, but you can feel disappointed when it is not reciprocated.")
elif n==10:
f.write("\n Aquarius - You will managae to find time today to spend with family")
elif n==11:
f.write("\n Pisces - Family get-together will give you a chance to mingle with cousins and other relatives")
f.seek(0)
q= f.read()
print(q)
f.close()
#File Handeling using W+
ReplyDeletes = open("C:/Users/abhis/Desktop/Abhifilehandeling/resume.txt","w+")
s.write('"Our courses"')
s.write("\n1> Python")
s.write("\n2> Java")
s.write("\n3> php")
s.write("\n4> Software Testing")
s.write("\n5> ASP.Net")
s.write("\n6> Advance Java")
s.write("\n7> Angular")
s.write("\n")
s.write('"\n> Visit our institute website:- https://shivaconceptsolution.com/"')
s.write("\n")
s.write('"\n> Address:- M6 First Floor, Kanchan Sagar, Near Industry House, Palasia Indore"')
s.write('"\n> Email us:- shivasirtutorials@gmail.com"')
s.write("\n> Call at :- H.O. 07805063968, 0731-4069788")
s.close()
___________________________________________________________
OUTPUT:-
"Our courses"
1> Python
2> Java
3> php
4> Software Testing
5> ASP.Net
6> Advance Java
7> Angular
"
> Visit our institute website:- https://shivaconceptsolution.com/"
"
> Address:- M6 First Floor, Kanchan Sagar, Near Industry House, Palasia Indore""
> Email us:- shivasirtutorials@gmail.com"
> Call at :- H.O. 07805063968, 0731-4069788
data=open("student.txt","w+")
ReplyDeletedata.write("Biodata of the student")
data.write("\n Name = Pritesh Mahajan")
data.write("\n Mobile Number = 8889615090")
data.write("\n Date of Birth = 1/Nov/1997")
data.write("\n Gender = Male")
data.write("\n Blood Group = O+")
data.write("\n Email ID = priteshmahajan@gmail.com")
data.write("\n Educational Qualification =B.E(Mechanical)")
data.write("\n Marital Status = Single")
data.write("\n Nationality = Indian")
data.write("\n Religion = Hindu")
data.write("\n Permanent Address = Ring Road Near Radisson blu Hotel")
data.write("\n Hobbies = Cricket, Gymming")
data.write("\n Language Known =Hindi, English")
data.close()
#MArksheet manager
ReplyDeletef=open("Marksheet.text","a+")
name= input("Enter name:")
physics=input("Enter physics marks:")
chemistry=input("Enter chemistry marks:")
maths=input("Enter maths marks:")
f.write("\n")
f.write("Student name:"+name)
f.write("\n")
f.write("Physics marks:"+physics)
f.write("\n")
f.write("Chemistry marks:"+chemistry)
f.write("\n")
f.write("Maths marks:"+maths)
f.seek(0)
data=f.readlines()
x=0
for i in data:
if i[0]=="P" or i[0]=="C" or i[0]=="M":
x=x+int(i[i.find(":")+1:])
print("The total marks is:",x)
f.close()
#Marksheet.
ReplyDeletemath = float(input("enter marks: "))
hindi = float(input("enter marks: "))
english = float(input("enter mark: "))
physics = float(input("enter mark: "))
chemistery = float(input("enter mark: "))
total = math+hindi+english+physics+chemistery
per = total/5
print("per is","=",per,"%")
data = open("Marksheetusingfilehandeling.txt","w+")
data.write("-----Abhishek Parihar-----")
data.write("\n")
data.write(" Math: "+str(math)+ "\n Hindi: "+str(hindi)+ "\n English: "+str(english)+ "\n Physics: "+str(physics)+ "\n Chemistery: "+str(chemistery))
data.write("\n")
data.write("> result is "+str(per))
data.write("\n")
data.write("Pass")
data.seek(0)
f=data.read()
print(f)
data.close()
__________________
output
__________
-----Abhishek Parihar-----
Math: 87.0
Hindi: 78.0
English: 89.0
Physics: 90.0
Chemistery: 92.0
> result is 87.2
Pass
#WAP to using write methad "w"?
ReplyDeletef = open("E://FileSachin.txt","w")
f.write("My first program using file handling")
f.close()
#WAP to using read methad "r"?
ReplyDeletef = open("E://FileSachin.txt","r")
s=f.read()
print(s)
f.close()
#Create Student Details System using File Handling Program:-
ReplyDeleteimport time
f = open("E://Filesachin2.txt","w")
stdname = input("Enter Student Name ")
address = input("Enter Student address ")
rollno = int(input("Enter Student Roll Number "))
college = input("Enter Student college Name ")
date = time.asctime(time.localtime(time.time()))
f.write("Sudent Details")
f.write("\n")
f.write("Student Name:"+stdname)
f.write("\n")
f.write("Student Adress:"+address)
f.write("\n")
f.write("Student Roll Number:"+str(rollno))
f.write("\n")
f.write("Student College Name:"+college)
f.write("\n")
f.write("date:"+date)
f.close()
#Student Details System program to append mode:-
ReplyDeleteimport time
f = open("E://Filesachin2.txt","a")
stdname = input("Enter Student Name ")
adress = input("Enter Student Adress ")
rollno = int(input("Enter Student Roll Number "))
collegename = input("Enter Student College Name ")
date = time.asctime(time.localtime(time.time()))
f.write("Student Details")
f.write("Student Name:"+stdname)
f.write("\n")
f.write("Student adress:"+adress)
f.write("\n")
f.write("Student Roll Number:"+str(rollno))
f.write("\n")
f.write("Student college Neme:"+collegename)
f.write("\n")
f.write("Date"+date)
f.close()
#Wap To Calculate Triangele Using File Handling "W+" ?
ReplyDeletebase = int(input("enter Base "))
heigth = int(input("Enter heigth "))
Area = (base*heigth)/2
f = open("E://Filesachin3.txt","w+")
f.write("\n Base of Triangle "+str(base) + "\n Heigth of Triangle "+str(heigth))
f.write("\n Area Is "+str(Area))
f.seek(0)
data = f.read()
print(data)
f.close()
#@WAP to perform the addition of two numbers and write the output of addition under file?
ReplyDeletef=open("C:\\files\\add.txt","w")
a=int(input("1:"))
b=int(input("2:"))
c=a+b
f.write(f"result of addition: {c}")
f.close()
Pawan singh Rathore
ReplyDeleteBatch (11 AM to 12 PM )
import time
f=open("Resume1.doc","w")
name=input("enter your name")
mobile=int(input("enter mobile number"))
email=input("enter email id")
address=input("enter your address")
graduation=input("enter graduation")
school1=input("enter higher secondary")
school2=input("enter higher secondary")
sub=input("enter sub")
father_name=input("enter father name")
dob=input("enter dob")
marital=input("enter marital")
gender=input("enter gender")
nationlity=input("enter nation")
date=time.asctime(time.localtime(time.time()))
place=input("enter place")
f.write(name+"\n")
f.write("Mobile:"+str(mobile)+"\n")
f.write("Email:"+str(email)+"\n")
f.write("Address:"+str(address)+"\n")
f.write("\nCARRIER OBJECTIVE \n")
f.write("I am seeking job and i will work with full honesty and learn new skills \n")
f.write("\nQUALIFICATION \n")
f.write("Graduation "+graduation+"\n")
f.write(str(school1)+"\n")
f.write(str(school2)+"\n")
f.write("\nTRANING \n")
f.write(str(sub)+"\n")
f.write("\nPERSONAL PROFILE \n")
f.write("Father Name :"+str(father_name)+"\n")
f.write("Date of Birth :"+str(dob)+"\n")
f.write("Marital status :"+str(marital)+"\n")
f.write("Gender :"+str(gender)+"\n")
f.write("Nationality :"+str(nationlity)+"\n")
f.write("\nDECLARATION \n")
f.write("I hereby declare that all the information given above is true and authentic as per my knowledge.\n")
f.write("\nDate :"+str(date)+"\n")
f.write("Place :"+str(place)+"\n")
f.close()