Wednesday, February 15, 2012

Python


info = []

info.append(input("Please enter your first name: "))
info.append(input("Please enter your last name: "))
info.append(input("Please enter your phone number: "))
info.append(input("Please enter your email: "))

contact = repr(info)

try:
f = open('contact_list.dat', 'a')
except:
f = open('contact_list.dat', 'w')

f.write(contact + "\n")
f.close()


We start with an empty list called info.
Then we store their info and turn it into a string using repr.
We create a file with the name contact_list.dat and the a (append)stores and makes it able to write more info in there after the program has been already created.

No comments:

Post a Comment