I have currently built a database (based on IMDB) that i can add dictionaries too, list them and exit.
I will put the program so far at the bottom of the page, just paste it in and run ti to see what it's like.
I am trying to add a third option that allows the user to view a single entry.
I have started this but need a lil' help.
I need to make it so that everytime an entry is added it is given a number that goes up.
1st entry =1
2nd entry = 2
and so on.
how can i make it give it a number that progressivly goes up?
is it something like
i=1
.....
item[i=+1]
or something, thats doesnt seem to work.
hope it isnt too complicated for you.
----------------------------------------------------------------
# A list of entries
# Each element will be a dictionary
records = []
# User input
user = ""
while user!="0":
#display menu
print
print " Film Database"
print "-----------------"
print "1 -- Add Entry"
print "2 -- List Entries"
print "3 -- List Single Entry"
print "4 -- Delete Single Entry"
print "0 -- Exit"
print "-----------------"
print len(records), "entries."
print
print "Enter option:",
#Get user input
user=raw_input()
if user=="1":
#Add to database
#create empty dictionary
item={}
print "Enter title:"
item["Title"]=raw_input()
print "Enter director:",
item["Director"]=raw_input()
print "Enter year:"
item["Year"]=raw_input()
records.append(item)
elif user=="2":
#display database
print '-'*10
for r in records:
print "Title: ",r["Title"]
print "Year: ",r["Year"]
print "Director:",r["Director"]
print "-"*10
print
elif user=="3":
#ask for which entry to view
print "-"*10
entry = int(raw_input('entry: '))
else:
print "Unknown option"