Skip to content

Instantly share code, notes, and snippets.

@jonaslsaa
Created May 25, 2015 12:19
Show Gist options
  • Select an option

  • Save jonaslsaa/063aeef0550f9c13be0c to your computer and use it in GitHub Desktop.

Select an option

Save jonaslsaa/063aeef0550f9c13be0c to your computer and use it in GitHub Desktop.
School System Official Release 2.4
#Python 3.4
import pickle
pupil = []
def menu():
print("\n*****************CLASS REGISTER*****************")
print("Press 1 See The List Of Pupils")
print("Press 2 To Add New Pupils")
print("Press 3 To Remove Pupils")
print("Press 4 To Import Datebase")
print("Press 5 To Export Database")
print("Press 0 To Quit ")
try: #Load
pickle_in = open("pupil_db.pickle", "rb")
pupil = pickle.load(pickle_in)
except: #Create/Write to pickle
pickle_out = open("pupil_db.pickle","wb")
pickle.dump(pupil, pickle_out)
pickle_out.close()
def see_list(x):
print('Pupils: \n')
for i in x:
print(i)
def add_pupil(x):
print("You have chosen to add a new pupil.\n")
option = input("Please type the childs name: ")
if option not in x:
x.append(option)
print(option, "has been added to the system.")
else:
print(str(option) + " is already in the system.")
return x
def delete_pupil(x):
print('\nYou have chosen to remove a pupil.\n')
option = input("Please type the childs name: ")
if option in x:
x.remove(option)
print(option, "has been removed from the system.")
else:
print(str(option) + " is not in the system.")
return x
def import_db(pupil):
print("You have chosen to import a new database.\n")
file_name = input("Please type in database file name: ")
db = open(file_name,"r")
for line in iter(db):
pupil.append(line.replace("\n",""))
print("Imported: "+line.replace("\n",""))
def export_db(pupil):
print("You have chosen to export the systems database to a file.\n")
file_name = input("Database file name: ")
fo = open(file_name, "a")
for i in pupil:
fo.writelines(i+"\n")
one = 1
while one != 0:
menu()
pickle_out = open("pupil_db.pickle","wb")
pickle.dump(pupil, pickle_out)
pickle_out.close()
option = input('Option: ')
print("\n"*50)
if int(option) == 1:
see_list(pupil)
elif int(option) == 2:
add_pupil(pupil)
elif int(option) == 3:
delete_pupil(pupil)
elif int(option) == 4:
import_db(pupil)
elif int(option) == 5:
export_db(pupil)
elif int(option) == 0:
break
else:
print("That is not a valible choice.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment