Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- try:
- import os,random,datetime
- from datetime import date
- except:
- print ("Modules required to run this program are not currently installed! Please install the required modules!")
- input()
- quit()
- def main():
- option = "Z"
- today = datetime.date.today()
- today = today.strftime("%A-%d-%B-%Y")
- print()
- print("Welcome to the Hogwarts School of Witchcraft and Wizardry student database!")
- print()
- #authentication()
- open_database("students.txt")
- print(today)
- print()
- print("====================MAIN MENU====================")
- print()
- print("What wish may I grant you today, squib?")
- print()
- print("Option A will allow you to add a new student to the Hogwarts database.")
- print("Option D will show all current students attending Hogwarts.")
- print("Option H will allow you to update the hogsmeade list for all students who can attend.")
- print("Option P will allow you to add House Points to a pupil.")
- print("Option N will allow you to add a new admin account for this program!")
- while option != "Q":
- option = input("Please choose an option (A,D,H,P,N or Q to exit!)")
- option = option.upper()
- if option == "Q":
- print("Thank you for using this program!")
- quit
- elif option == "A":
- os.system("cls")
- new_student()
- elif option == "D":
- os.system("cls")
- show_all()
- elif option == "H":
- os.system("cls")
- hogsmeade_trip()
- elif option == "P":
- os.system("cls")
- add_points()
- elif option == "N":
- new_user()
- #WIP could be improved but not required (All users and passwords stored in an (encrypted?) text file rather than in the source code itself)
- def authentication():
- authenticated = False
- user1 = "Hog"
- pass1 = "warts"
- print("To access the Hogwarts students database, authentication is required!")
- while authenticated == False:
- user = input("Please input your username: ")
- if user == user1:
- password = input("Please input your password: ")
- if password == pass1:
- authenticated = True
- os.system("cls")
- else:
- print("Wrong password!")
- else:
- print("Wrong username")
- authenticated = False
- def open_database(fname):
- txt = open(fname,"a+")
- txt.seek(0)
- global student_list
- student_list = []
- lines = txt.readlines()
- for l in lines:
- l = l.replace("\n","")
- student_list.append(l.split(","))
- def new_student():
- print()
- print("--------------------Welcome to the Student Creation Menu!--------------------")
- print()
- validation = False
- houses = ["Slytherin","Gryffindor","Hufflepuff","Ravenclaw"]
- name = input("Last Name of student? Can not contain numbers!")
- while name.isalpha() == False:
- print("I said no numbers! How many people do you know with numbers in their names?")
- name = input("Last Name of student? Can not contain numbers!")
- name = name.title()
- #Misunderstanding with instruction, says it needs 3 random numbers after the 3 first letters of their name but examples only have 2?
- #Decided to go with the other examples and make it 2.
- random_number = str(random.randint(10,99))
- today = datetime.date.today()
- year = today.strftime("%y")
- student_id = name[0:3]+random_number+year
- print(student_id)
- housepoints = 0
- hogsmeade = 0
- join_date = today.strftime("%Y")
- while validation == False:
- try:
- house_check = int(input("Would you like to assign the pupil to a house yourself(0) or should the system randomly assign the student to a house(1)?"))
- except:
- print("Invalid input! Please type either 0 or 1!")
- continue
- if house_check == 0:
- validation = True
- house = input("What house do you wish the student to be in?")
- house = house.title()
- while house not in houses:
- print("That is not a valid house!Please try again! Remember, spelling matters!")
- house = input("What house do you wish the student to be in?")
- house = house.title()
- elif house_check == 1:
- print("The student's house will now be randomly generated!")
- house = houses[1]
- print("%s is now in the %s house!" % (student_id, house))
- validation = True
- else:
- continue
- new_list = [student_id,name,join_date,house,housepoints,hogsmeade]
- print (new_list)
- def show_all():
- print()
- print("Students currently attending Hogwarts: \n")
- print("Student_ID,Name,JoinDate,House,HousePoints,HogsmeadeTrips")
- formatted_list = str(student_list)
- formatted_list = formatted_list.replace("], [","\n")
- formatted_list = formatted_list.replace("[","")
- formatted_list = formatted_list.replace("]","")
- formatted_list = formatted_list.replace("'","")
- print (formatted_list)
- input("Press [Enter] to go to the MAIN MENU.")
- def hogsmeade_trip():
- pass
- def add_points():
- pass
- def new_user():
- pass
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement