-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile_input.py
More file actions
124 lines (87 loc) · 2.79 KB
/
file_input.py
File metadata and controls
124 lines (87 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# f= open("demo.txt" , "r")
# data =f.read()
# print(data)
# print(type(data))
# f.closed
# f= open("demo.txt" , "rt")
# data =f.read()
# print(data)
# print(type(data))
# f.closed
# f= open("demo.txt" , "r+") # for read and write
# data =f.read()
# print(data)
# print(type(data))
# f.closed
# f= open("demo.txt" , "W+")
# data =f.read()
# print(data)
# print(type(data))
# f.closed
# f= open("demo.txt" , "X+") #for creating anew file
# data =f.read()
# print(data)
# print(type(data))
# f.closed
# f= open("demo.txt" , "a+") # open for writing and appending to the end of file
# data =f.read(5)
# line1=f.readline() # which print the the five character
# print(line1)
# print(type(line1))
# f.closed
# f= open("demo.txt" , "W+") #it deletes my file and rewrite it again
# data =f.write("I want to learn java script tomorrow.")
# f.closed
# with open("demo.txt" , "W+") as f #it deletes my file and rewrite it again
# data =f.write("I want to learn java script tomorrow.")
# print(data)
# Modules
# OS module
# import os
# os.remove("demo.txt")
# Some practice question
# Create a new file “practice.txt” using python. Add the following data in it:
# WAF that replace all occurrences of “java” with “python” in above file.
# Search if the word “learning” exists in the file or not.
# with open ("Practice.txt","w") as f:
# f.write("Hi every one . I am Talha. and\nwe are learning File I/O in Python.\n")
# f.write("Using java.\nI like programming in java.")
# with open ("Practice.txt","r") as f:
# data=f.read()
# new_data=data.replace("java","python")
# print(new_data)
# with open ("Practice.txt","w") as f:
# f.write(new_data)
# word="learning"
# with open ("practice.txt","r")as f:
# data=f.read()
# if data.find(word) !=-1:
# print("Found")
# else:
# print("not found")
# def check_for_line():
# word="learning"
# line_no =1
# data=True
# with open ("practice.txt","r")as f:
# while data:
# data=f.readline()
# if (word in data):
# print(line_no)
# return
# line_no+=1
# return-1
# check_for_line()
#From a file containing numbers separated by comma, print the count of even numbers.
with open ("make.txt","w") as f:
f.write("1,2,76,84,90,101")
with open ("make.txt","r") as f:
data=f.read()
count=0
nums=data.split(",")
print(nums)
for value in nums:
if (int(value) % 2==0):
print(value)
count+=1
print("number of even value is :" ,count)