Advertisement
Guest User

Untitled

a guest
Jun 21st, 2017
595
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.64 KB | None | 0 0
  1. # MAIN VARIABLES
  2. import time
  3. tutor = "Mr.Leeman"
  4. username = "Leeman"
  5. password = "Donut123"
  6. file = open('details.txt','r')
  7. details = file.readlines()
  8. loop = True
  9. ID = len(details)
  10. append = open('details.txt','a')
  11.  
  12. # FUNCTIONS
  13.  
  14. # LOGIN
  15. def login():
  16.     print("Welcome to the Tutor Group Manager\nHit q to quit the program.")
  17.     while loop == True:
  18.         userinput = input("\nUSERNAME:")
  19.         if userinput == "q":
  20.             file.close()
  21.             quit()
  22.         passinput = input("PASSWORD:")
  23.         if userinput == username and passinput == password:
  24.             mainmenu()
  25.         elif passinput == "q":
  26.             file.close()
  27.             append.close()
  28.             quit()
  29.         else:
  30.             print("Wrong details given!")
  31.  
  32. # MAIN MENU
  33. def mainmenu():
  34.     print("\n          Main Menu")
  35.     print("\n(1)Enter new student details")
  36.     print("(2)Access student details")
  37.     print("(3)Special reports")
  38.     print("(4)Log out")
  39.     menu = input(" O>")
  40.     if menu == "1":
  41.         newdata(ID,append)
  42.     elif menu == "2":
  43.         accessdata(details)
  44.     elif menu == "3":
  45.         print("Special reports")
  46.     elif menu == "4":
  47.         print("")
  48.         login()
  49.     else:
  50.         print("Wrong input given!")
  51.         time.sleep(2)
  52.         print("")
  53.         mainmenu()
  54. # 1ST OPTION
  55. def newdata(ID,append):
  56.     print("Enter new student details below:")
  57.     surname = input("SURNAME:")
  58.     forename = input("FORENAME:")
  59.     dob = input("DATE OF BIRTH(day/month/year format):")
  60.     address = input("ADDRESS:")
  61.     phone = input("PHONE NUMBER:")
  62.    
  63.     if len(phone) < 9:
  64.         print("The phone number is too short, has to be at least 9 digits")
  65.         newdata(ID,append)
  66.        
  67.     gender = input("GENDER(M/F):")
  68.  
  69.     if gender == "M":
  70.         gender = "Male"
  71.     elif gender == "F":
  72.         gender = "Female"
  73.     else:
  74.         print("Wrong Gender given! Has to be M(Male) or F(Female)")
  75.         newdata(ID,append)
  76.    
  77.     email = input("EMAIL ADDRESS(name.surname@treeroad.co.uk):")
  78.  
  79.     if "@treeroad.co.uk" not in email:
  80.         print("Wrong email address given!")
  81.         newdata(ID,append)
  82.                
  83.     print("ID = ",ID)
  84.     print("SURNAME = ",surname)
  85.     print("FORENAME = ",forename)
  86.     print("DATE OF BIRTH = ",dob)
  87.     print("ADDRESS = ",address)
  88.     print("PHONE NUMBER = ",phone)
  89.     print("GENDER = ",gender)
  90.     print("Tutor Group = ",tutor)
  91.     print("EMAIL ADDRESS = ",email)
  92.     approval = input("Are you satisfied with the data given?(Y/N)")
  93.    
  94.  
  95.     if approval == "Y" or approval == "y":
  96.         ID = str(ID)
  97.         append.write("\n")
  98.         append.write(ID)
  99.         append.write(",")
  100.         append.write(surname)
  101.         append.write(",")
  102.         append.write(forename)
  103.         append.write(",")
  104.         append.write(dob)
  105.         append.write(",")
  106.         append.write(address)
  107.         append.write(",")
  108.         append.write(phone)
  109.         append.write(",")
  110.         append.write(gender)
  111.         append.write(",")
  112.         append.write(tutor)
  113.         append.write(",")
  114.         append.write(email)
  115.         ID = int(ID)
  116.         ID = ID + 1
  117.         print ("New ID = ",ID)
  118.        
  119.         print("Data saved!")
  120.         time.sleep(1)
  121.         mainmenu()
  122.     elif approval == "N" or approval == "n":
  123.         ID = int(ID)
  124.         ID = ID - 1
  125.         ID = str(ID)
  126.         newdata(ID,append)
  127.     else:
  128.         print("Wrong input!")
  129.         ID = int(ID)
  130.         ID = ID - 1
  131.         ID = str(ID)
  132.         newdata(ID,append)
  133.  
  134. def accessdata(details):
  135.     ran = len(details)
  136.     idinput = input("Enter the personalized ID:")
  137.     print("Accessed")
  138.     for x in range(ran):
  139.         print("Accessed")
  140.         split = details[x].split(",")
  141.         print(split[0])
  142.         if split[0] == idinput:
  143.             print("ID = ",split[0])
  144.             print("SURNAME = ",split[0])
  145.             print("FORENAME = ",split[0])
  146.             print("DATE OF BIRTH = ",split[0])
  147.             print("ADDRESS = ",)
  148.             print("PHONE NUMBER = ",phone)
  149.             print("GENDER = ",gender)
  150.             print("Tutor Group = ",tutor)
  151.             print("EMAIL ADDRESS = ",email)
  152.             print("\n(1)Search for another student")
  153.             print("(2)Go back to main menu")
  154.             accessinput = input("O>")
  155.             if accessinput == "1":
  156.                 accessdata(details)
  157.             elif accessinput == "2":
  158.                 mainmenu()
  159.             else:
  160.                 print("Wrong input given!")
  161.                 time.sleep(1)
  162.                 accessdata(details)
  163.         else:
  164.             print("Not found")
  165.    
  166. # MAIN PROGRAM    
  167. login()
  168. # END OF CODE :)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement