Check sibling questions
Computer Science - Class 12
Chapter 2 - File Handling in Python

Create file phonebook.dat that stores the details in

following format: 

Name Phone

Jivin 86666000 

Kriti 1010101 

Obtain the details from the user.

 

Answer:

f=open( "phonebook.dat" , 'w' )

f.write( "Name Phone\n" )

while True:

    name=input( "Enter name:" )

    phone=input( "Enter phone number: " )

    f.write(name+ " " +phone+ "\n" )

    more=input( "Want to enter more? Enter Y if yes: " )

    if more.upper() != 'Y' :

        break

f.close()

Question 3-Create file phonebook - Teachoo.JPG

File phonebook.dat:

image2.png

Introducing your new favourite teacher - Teachoo Black, at only ₹83 per month


Transcript

Question 3 Create file phonebook.dat that stores the details in following format: Name Phone Jivin 86666000 Kriti 1010101 Obtain the details from the user. Opens file phonebook.dat in write mode Accepts user input ‘name’ and ‘phone’ and writes it to the file Output Writes data to the file Closes the file

CA Maninder Singh's photo - Expert in Practical Accounts, Taxation and Efiling

Made by

CA Maninder Singh

CA Maninder Singh is a Chartered Accountant for the past 12 years. He also provides Accounts Tax GST Training in Delhi, Kerala and online.