Skip to content

Commit 0e1fca4

Browse files
committed
python
1 parent 99ed05f commit 0e1fca4

7 files changed

+42
-2
lines changed

day31(readwritelines).py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
f = open('marks.txt', 'r')
2+
i = 0
3+
while True:
4+
i = i + 1
5+
line = f.readline()
6+
if not line:
7+
break
8+
9+
m1 = int(line.split(",")[0])
10+
m2 = int(line.split(",")[1])
11+
m3 = int(line.split(",")[2])
12+
print(f"Marks of student {i} in Maths is: {m1*2}")
13+
print(f"Marks of student {i} in English is: {m2*2}")
14+
print(f"Marks of student {i} in SST is: {m3*2}")
15+
16+
print(line)

day32(seek tell).py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# with open('file.txt','w') as f:
2+
# print(f) # use kiye naya text file crate krne ke liye
3+
4+
# NOW
5+
6+
with open('file.txt','r') as f:
7+
print(type(f))
8+
f.seek(11) #move 11 byte in the file
9+
print(f.tell())
10+
data =f.read(5) # wha se next 5 character read karega
11+
print(data)
12+
13+
14+

day33(truncate).py

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
with open ('filetru.txt','w') as f :
2+
print(f)
3+
f.write('Hello World!')
4+
f.truncate(5) # ye 5 byte tk hi truncate kr dega jo v wirte karana hoga so

file.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
123456789tetvihsalsoinghkashyap

filetru.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hello

marks.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
24,45,67
2+
89,67,20
3+
90,99,89

myfile.txt

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
I am a good guy pursuing B-Tech from KIIT university
2-
Hello, world!Hello, world!Hello, world!hey i mm inside the environmentHello, world!hey i mm inside the environment
1+
23,34,67
2+
78,90,23
3+
89,67,30

0 commit comments

Comments
 (0)