Tuesday, 23 April 2024

FILE INPUT OR OUTPUT


#  1. If You Want Creat a New File So
a = open("manan.txt", "w")
a.close()

#  2. if you want write on this file so

b = open("manan.txt", "w")
c = b.write("Hello Manan")
b.close()

# 3. If You Want Again Write In File So Used Append (a) If You Used Appand Write The text And text Is Add
# End Of The Text Of Is File.

d = open("manan.txt", "a")
e = d.write("\nYou Are Run The Program")
d.close()

#  An Other Method You Want Add text In File

with open('manan.txt', 'a')as f:
    f.write("\nHard Work In Pyhtone")

#  4. If You Want Read The Lines Of Folder So

g = open("manan.txt", "r")
while True:
    line = g.readlines()
    if not line:
        break
    print (line)

    #  5. If You Want User Input and Autamtically Save In File So

    age = int(input("Enter Your Age: "))
    h = open("manan.txt", "a")
    h.write(age)
    h.close()

No comments:

Post a Comment

MAKE A CALANDER

  # 1.  convert calander year and month. your choice month or year , print while True :   import calendar   year = int ( input ( "P...