File Handling 21: Read and write to file. student details

# Read student details and write to file

fs = open("stu.txt","w+")

NumStu = int(input("Enter number of students : "))
counter = 0
while(counter<NumStu):
    name = input("Enter name : ").strip()
    rno = int(input("Enter number : "))
    cgpa = float(input("Enter cgpa : "))
   
    fs.write(name+" "+str(rno)+" "+str(cgpa)+"\n")

    counter+=1


print("Displaying student details:")
fs.seek(0,0)
while(True):
    line = fs.readline()
    if not line:
        break
    print(line)
fs.close()

No comments:

Post a Comment

Don't be a silent reader...
Leave your comments...

Anu