Advertisement
Guest User

Untitled

a guest
Sep 1st, 2017
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.32 KB | None | 0 0
  1. try:
  2.     import os,random,datetime
  3.     from datetime import date
  4. except:
  5.     print ("Modules required to run this program are not currently installed! Please install the required modules!")
  6.     input()
  7.     quit()
  8. def main():
  9.     option = "Z"
  10.     today = datetime.date.today()
  11.     today = today.strftime("%A-%d-%B-%Y")
  12.     print()
  13.     print("Welcome to the Hogwarts School of Witchcraft and Wizardry student database!")
  14.     print()
  15.     #authentication()
  16.     open_database("students.txt")
  17.     print(today)
  18.     print()
  19.     print("====================MAIN MENU====================")
  20.     print()
  21.     print("What wish may I grant you today, squib?")
  22.     print()
  23.     print("Option A will allow you to add a new student to the Hogwarts database.")
  24.     print("Option D will show all current students attending Hogwarts.")
  25.     print("Option H will allow you to update the hogsmeade list for all students who can attend.")
  26.     print("Option P will allow you to add House Points to a pupil.")
  27.     print("Option N will allow you to add a new admin account for this program!")
  28.     while option != "Q":
  29.         option = input("Please choose an option (A,D,H,P,N or Q to exit!)")
  30.         option = option.upper()
  31.         if option == "Q":
  32.             print("Thank you for using this program!")
  33.             quit
  34.         elif option == "A":
  35.             os.system("cls")
  36.             new_student()
  37.         elif option == "D":
  38.             os.system("cls")
  39.             show_all()
  40.         elif option == "H":
  41.             os.system("cls")
  42.             hogsmeade_trip()
  43.         elif option == "P":
  44.             os.system("cls")
  45.             add_points()
  46.         elif option == "N":
  47.             new_user()
  48.    
  49. #WIP could be improved but not required (All users and passwords stored in an (encrypted?) text file rather than in the source code itself)
  50. def authentication():
  51.     authenticated = False
  52.     user1 = "Hog"
  53.     pass1 = "warts"
  54.     print("To access the Hogwarts students database, authentication is required!")    
  55.     while authenticated == False:
  56.         user = input("Please input your username: ")
  57.         if user == user1:
  58.             password = input("Please input your password: ")
  59.             if password == pass1:
  60.                 authenticated = True
  61.                 os.system("cls")
  62.             else:
  63.                 print("Wrong password!")
  64.         else:
  65.             print("Wrong username")
  66.             authenticated = False
  67.  
  68. def open_database(fname):
  69.     txt = open(fname,"a+")
  70.     txt.seek(0)
  71.     global student_list
  72.     student_list = []
  73.     lines = txt.readlines()
  74.     for l in lines:
  75.         l = l.replace("\n","")
  76.         student_list.append(l.split(","))
  77.    
  78.  
  79. def new_student():
  80.     print()
  81.     print("--------------------Welcome to the Student Creation Menu!--------------------")
  82.     print()
  83.     validation = False
  84.    
  85.     houses = ["Slytherin","Gryffindor","Hufflepuff","Ravenclaw"]
  86.     name = input("Last Name of student? Can not contain numbers!")
  87.    
  88.     while name.isalpha() == False:
  89.         print("I said no numbers! How many people do you know with numbers in their names?")
  90.         name = input("Last Name of student? Can not contain numbers!")
  91.     name = name.title()
  92.     #Misunderstanding with instruction, says it needs 3 random numbers after the 3 first letters of their name but examples only have 2?
  93.     #Decided to go with the other examples and make it 2.
  94.     random_number = str(random.randint(10,99))    
  95.     today = datetime.date.today()
  96.     year = today.strftime("%y")
  97.     student_id = name[0:3]+random_number+year
  98.     print(student_id)
  99.     housepoints = 0
  100.     hogsmeade = 0
  101.     join_date = today.strftime("%Y")
  102.     while validation == False:
  103.         try:
  104.             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)?"))
  105.         except:
  106.             print("Invalid input! Please type either 0 or 1!")
  107.             continue
  108.         if house_check == 0:
  109.             validation = True
  110.             house = input("What house do you wish the student to be in?")
  111.             house = house.title()
  112.             while house not in houses:
  113.                 print("That is not a valid house!Please try again! Remember, spelling matters!")
  114.                 house = input("What house do you wish the student to be in?")
  115.                 house = house.title()
  116.         elif house_check == 1:
  117.             print("The student's house will now be randomly generated!")
  118.             house = houses[1]
  119.             print("%s is now in the %s house!" % (student_id, house))
  120.             validation = True
  121.         else:
  122.             continue
  123.     new_list = [student_id,name,join_date,house,housepoints,hogsmeade]
  124.     print (new_list)
  125.  
  126.  
  127. def show_all():
  128.     print()
  129.     print("Students currently attending Hogwarts: \n")
  130.     print("Student_ID,Name,JoinDate,House,HousePoints,HogsmeadeTrips")
  131.     formatted_list = str(student_list)
  132.     formatted_list = formatted_list.replace("], [","\n")
  133.     formatted_list = formatted_list.replace("[","")
  134.     formatted_list = formatted_list.replace("]","")
  135.     formatted_list = formatted_list.replace("'","")
  136.     print (formatted_list)
  137.     input("Press [Enter] to go to the MAIN MENU.")
  138.  
  139. def hogsmeade_trip():
  140.     pass
  141.  
  142. def add_points():
  143.     pass
  144.  
  145. def new_user():
  146.     pass
  147. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement