Advertisement
Guest User

Untitled

a guest
Oct 15th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.30 KB | None | 0 0
  1. ### CHANGES TO THE CODE: ###
  2. # Try,except error handling for ValueError in the menu and search menu
  3. # Fixed the search errors
  4.  
  5.  
  6.  
  7.  
  8. # Importing time library for aesthetics
  9. import time
  10.  
  11. ### LOGIN ###
  12. print("Welcome Mr Leeman, to your personal tutor group manager, Please log in (CaSe SeNsItIvE).")
  13. username ="Mr Leeman"
  14. password ="TreeRoad" # defining the functions
  15. UserInput=input("Enter Username: ")#Mr Leeman enters username
  16. PassInput=input("Enter Password: ")#Mr Leeman enters password
  17. if not UserInput.strip():
  18. print("You must not leave any areas blank!")
  19. if not PassInput.strip():
  20. print("You must not leave any areas blank!")
  21.  
  22. trials = 0
  23. while (PassInput != password or UserInput != username): #while Mr Leemchoice input for his credentials to not match expected
  24. if trials==2: # if he takes 3 tries
  25. exit() # then exit program
  26. else: # otherwise
  27. UserInput=input("Your username or password was incorrect: Re-Enter Username ") #if he has tried once or twice
  28. PassInput=input("Re-Enter Password ")# make him reenter credentials
  29.  
  30. trials+=1 # every time he fails an attempt, log it.
  31. if (PassInput == password and username == UserInput): # if Mr Leemchoice input matches the expected
  32. print("You have been logged in successfully " + UserInput) # informs Mr Leeman of his login
  33. time.sleep(1.5)
  34. def menu():
  35. try:
  36. # Simple menu
  37. print("Tutor Group Management System")
  38. print("(1) Add a new student")
  39. print("(2) Search for a student with id number")
  40. print("(3) View student details")
  41. print("(4) Quit")
  42. print("(5) View reports")
  43. Menu = int(input(":"))
  44. if Menu == 1:
  45. addStudent()
  46. elif Menu == 2:
  47. searchStudent()
  48. elif Menu == 3:
  49. studentDetails()
  50. elif Menu == 4:
  51. print("Exiting...")
  52. time.sleep(1)
  53. quit()
  54.  
  55. except(ValueError):
  56. print("Wrong input given (Must be 1,2,3 or 4)")
  57. time.sleep(1.5)
  58. menu()
  59. ### END OF menu() ###
  60.  
  61. ### ADD A NEW BOOK ###
  62. def addStudent():
  63. # Open/create a file holding the book data
  64. data = open("students.txt",'a+')
  65.  
  66. # Collect the data to be saved
  67. uniqueid = (input("uniqueid of the student = ")).upper()
  68. fullname = (input("Full name and Date of birth = ")).upper()
  69. homeinfo = (input("Home number and address = ")).upper()
  70. schoolinfo = (input("Assigned tutor group and email = "))
  71.  
  72. # Save the data with commas separating them for easier splitting
  73. data.write(uniqueid + "," + fullname + "," + homeinfo + "," + schoolinfo + "")
  74. data.close()
  75. print("Data Saved!")
  76.  
  77. # Ask the user if he wants to add another book
  78. repeat = input("Would you like to add another student? (Y/N)")
  79.  
  80. if repeat == "Y" or repeat == "y" or repeat == "Yes":
  81. addStudent()
  82. elif repeat == "n" or repeat == "N" or repeat == "No":
  83. print("Returning to main menu...")
  84. time.sleep(1.5)
  85. menu()
  86. else:
  87. print("Wrong input received! Returning to main menu...")
  88. time.sleep(1)
  89. menu()
  90.  
  91. ### END OF addStudent() ###
  92.  
  93. ### SEARCH FOR A BOOK ###
  94. def searchStudent():
  95. with open('students.txt', 'r') as searchfile
  96. for line in searchfile:
  97. if 'searchphrase' in line:
  98. print line
  99. # homeinfo search
  100. elif criteria == 2:
  101.  
  102. shomeinfo = input("Enter the desired homeinfo = ")
  103. print("Books that match your criteria")
  104. time.sleep(0.2)
  105.  
  106. for line in bookDetails:
  107. fhomeinfo = (line.strip("")).split(",")
  108.  
  109. # If the homeinfo in the file is equal to the homeinfo given then:
  110. if shomeinfo.upper() == fhomeinfo[2]:
  111.  
  112. # Display the book details
  113. print("uniqueid = ",fhomeinfo[0])
  114. time.sleep(0.015)
  115. print("fullname = ",fhomeinfo[1])
  116. time.sleep(0.015)
  117. print("homeinfo = ",fhomeinfo[2])
  118. time.sleep(0.015)
  119. print("Page Count = ",fhomeinfo[3],"")
  120. time.sleep(0.015)
  121.  
  122. input("Press ENTER to continue")
  123. menu()
  124.  
  125. else:
  126. print("Wrong input given.")
  127. time.sleep(1.5)
  128. searchStudent()
  129. except(ValueError):
  130. print("Wrong input given.")
  131. time.sleep(1.5)
  132. searchStudent()
  133. ### END OF searchStudent() ###
  134.  
  135. ### ADD A NEW CUSTOMER ###
  136. def studentDetails():
  137. # Open the file with student information
  138. f = open('students.txt', 'r')
  139.  
  140. # Let him view file
  141. file_contents = f.read()# gets everything from file
  142. print (file_contents)# print the file
  143. f.close()# close the file
  144. # Ask Mr Leeman if he wants to add another student
  145. repeat = input("Would you like to see it again? (Y/N)")
  146. if repeat == "Y":
  147. studentDetails()
  148. elif repeat == "N":
  149. menu()
  150. else:
  151. print("Wrong input given. Returning to main menu...")
  152. time.sleep(1.5)
  153. menu()#return to menu
  154.  
  155. ### END OF studentDetails() ###
  156.  
  157. menu()
  158.  
  159.  
  160. ### END OF THE PROGRAM ###
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement