In: Computer Science
Problem 2 (Save and Get Info) : Write a program
that asks for the user's name, phone number, and address. The
program then saves all information in a data file (each information
in one line) named list.txt. Finally, the program
reads the information from the file and displays it on the
screen in the following format:
Name: User's Name
Phone Number: User's Phone Number
Address: User's Street Address
User's City, State, and Zip Code
Note=> As it is not written in which programming langauage I am suposed to do it. So, I am solving it in python.
Code:
## This cell will add the data in a dictionoray and then store
that dictionary in file
import pickle
dict1={}
name=input("Enter Name: ")
phone=input("Enter Phone No: ")
address=input("Enter Address: ")
dict1['Name']=name
dict1['Phone Number']=phone
dict1['Address']=address
with open('/content/drive/My Drive/list.txt','wb' )as fp: #Addin
the path where we want to store the file as list1
pickle.dump(dict1,fp)
## Loading a data from file
with open('/content/drive/My Drive/list.txt','rb') as fp: ##
Reading a file from same location
dict1= pickle.load(fp)
for i in dict1.keys() : # iterationg over each key of
ditionary
print(i, " : ",dict1[i] )
Screenshots of code and output :
Storing a data into a file list1.txt.
Reading a data from file: