कंप्यूटर प्रोग्रामिंग/फ़ाइलें/पाइथन3
strings.py
सम्पादन# This program creates a file, adds data to the file, displays the file,
# appends more data to the file, displays the file, and then deletes the file.
# It will not run if the file already exists.
import os
def create_file(filename):
file = open(filename, "w")
file.write("C\tF\n")
for c in range(0, 51):
f = c * 9 / 5 + 32
file.write("%.1f\t%.1f\n" % (c, f))
file.close()
def read_file(filename):
file = open(filename, "r")
for line in file:
line = line.strip()
print(line)
file.close()
print("")
def append_file(filename):
file = open(filename, "a")
for c in range(51, 101):
f = c * 9 / 5 + 32
file.write("%.1f\t%.1f\n" % (c, f))
file.close()
def delete_file(filename):
os.remove(filename)
def main():
filename = "~file.txt"
if os.path.isfile(filename):
print("File already exists.")
else:
create_file(filename)
read_file(filename)
append_file(filename)
read_file(filename)
delete_file(filename)
main()
कोशिश करो
सम्पादननिम्न कोड मुफ्त ऑनलाइन विकास के वातावरण में से एक में ऊपर कॉपी और पेस्ट करो या अपने खुद के कम्पाइलर/इंटरप्रेटर/आईडीई का उपयोग करें।