create file and write numbers to file in python

Solutions on MaxInterview for create file and write numbers to file in python by the best coders in the world

showing results for - "create file and write numbers to file in python"
Isabel
13 Nov 2018
1##Write a Python program to create a file of numbers 
2##by taking input from the user and 
3##then display the content of the file. 
4##You can take input of non-zero numbers, 
5##with an appropriate prompt, from the user until the user enters a zero 
6#to create the file assuming that the numbers are non-zero.  
7    f = open ('NumFile.txt','w')
8    while True :
9        no = int(input("enter a number (0 for exit)"))
10        if no == 0 :
11            print("you entered zero(0) ....... \n now you are exit  !!!!!!!!!!!")
12            break
13        else :
14            f.write(str(no)+"\n")
15    f.close() 
16    f1 = open ('NumFile.txt','r')
17    print("\ncontent of file :: \n",f1.read())
18    f1.close()
19
20