Hello everyone. New to python as well as this forum, but i must say ive learned a but already reading through some posts. Seems to be a pretty helpful community here.
Before i post a question ill give you a little background. I have done programming in the past in Basic, VB, and a little C. I am not much of a programmer, its more of a hobby/curiosity.
The following code is not mine, i am trying to modify a template of a mock database. The options in the database are 0. Exit 1. Query 2. Append. 3 Delete. I am trying to use functions here, and they are defined at the top of the program. the code is as follows:
I am pretty sure the query function is correct, but i am not sure how to append to a database or to delete?
Before i post a question ill give you a little background. I have done programming in the past in Basic, VB, and a little C. I am not much of a programmer, its more of a hobby/curiosity.
The following code is not mine, i am trying to modify a template of a mock database. The options in the database are 0. Exit 1. Query 2. Append. 3 Delete. I am trying to use functions here, and they are defined at the top of the program. the code is as follows:
Code:
def query(course, grade): courseindex=database[0].index(course) for record in range(1,len(database),1): if database[record][courseindex]==grade: print database[record][0] print("\n") raw_input("press enter to continue\n\n\n") def append(name, math, English, Physics, Chemistry): print("The append function is to be written") raw_input("press enter to continue\n\n\n") def delete(ID): print("The delete function is to be written") raw_input("press enter to continue\n\n\n") #main #global variable database=[["name","ID","Math","English","Physics","Chemistry"]] database+=[["Tom",1,"A","B","B","C"]] database+=[["Chen",2,"B","C","D","A"]] database+=[["John",3,"C","B","A","D"]] database+=[["Andres",4,"D","A","C","B"]] Current_ID=5 #global variable choice = None while choice != "0": for record in range(0, len(database),1): row="" for attribute in range(0,len(database[record]),1): row+=str(database[record][attribute])+"," print row+"\n" print \ """ Welcome to Mini Database 0 - Exit 1 - Query 2 - Append 3 - Delete """ choice = raw_input("Choice: ") # exit if choice == "0": print "Good-bye." # query elif choice == "1": query(raw_input("What course you want to query?"), raw_input("What grade you want to query?")) elif choice=="2": append(raw_input("What is the student's name?"), raw_input("What is the student's grade for Math?(A/B/C/D/F)"), raw_input("What is the student's grade for English?(A/B/C/D/F)"), raw_input("What is the student's grade for Physics?(A/B/C/D/F)"), raw_input("What is the student's grade for Chemistry?(A/B/C/D/F)")) elif choice=="3": delete(int(raw_input("What is the student's ID?"))) # some unknown choice else: print "Sorry, but", choice, "isn't a valid choice." raw_input("press enter to finish the program")
I am pretty sure the query function is correct, but i am not sure how to append to a database or to delete?
Comment