Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ### CHANGES TO THE CODE: ###
- # Try,except error handling for ValueError in the menu and search menu
- # Fixed the search errors
- # Importing time library for aesthetics
- import time
- ### LOGIN ###
- print("Welcome Mr Leeman, to your personal tutor group manager, Please log in (CaSe SeNsItIvE).")
- username ="Mr Leeman"
- password ="TreeRoad" # defining the functions
- UserInput=input("Enter Username: ")#Mr Leeman enters username
- PassInput=input("Enter Password: ")#Mr Leeman enters password
- if not UserInput.strip():
- print("You must not leave any areas blank!")
- if not PassInput.strip():
- print("You must not leave any areas blank!")
- trials = 0
- while (PassInput != password or UserInput != username): #while Mr Leemchoice input for his credentials to not match expected
- if trials==2: # if he takes 3 tries
- exit() # then exit program
- else: # otherwise
- UserInput=input("Your username or password was incorrect: Re-Enter Username ") #if he has tried once or twice
- PassInput=input("Re-Enter Password ")# make him reenter credentials
- trials+=1 # every time he fails an attempt, log it.
- if (PassInput == password and username == UserInput): # if Mr Leemchoice input matches the expected
- print("You have been logged in successfully " + UserInput) # informs Mr Leeman of his login
- time.sleep(1.5)
- def menu():
- try:
- # Simple menu
- print("Tutor Group Management System")
- print("(1) Add a new student")
- print("(2) Search for a student with id number")
- print("(3) View student details")
- print("(4) Quit")
- print("(5) View reports")
- Menu = int(input(":"))
- if Menu == 1:
- addStudent()
- elif Menu == 2:
- searchStudent()
- elif Menu == 3:
- studentDetails()
- elif Menu == 4:
- print("Exiting...")
- time.sleep(1)
- quit()
- except(ValueError):
- print("Wrong input given (Must be 1,2,3 or 4)")
- time.sleep(1.5)
- menu()
- ### END OF menu() ###
- ### ADD A NEW BOOK ###
- def addStudent():
- # Open/create a file holding the book data
- data = open("students.txt",'a+')
- # Collect the data to be saved
- uniqueid = (input("uniqueid of the student = ")).upper()
- fullname = (input("Full name and Date of birth = ")).upper()
- homeinfo = (input("Home number and address = ")).upper()
- schoolinfo = (input("Assigned tutor group and email = "))
- # Save the data with commas separating them for easier splitting
- data.write(uniqueid + "," + fullname + "," + homeinfo + "," + schoolinfo + "")
- data.close()
- print("Data Saved!")
- # Ask the user if he wants to add another book
- repeat = input("Would you like to add another student? (Y/N)")
- if repeat == "Y" or repeat == "y" or repeat == "Yes":
- addStudent()
- elif repeat == "n" or repeat == "N" or repeat == "No":
- print("Returning to main menu...")
- time.sleep(1.5)
- menu()
- else:
- print("Wrong input received! Returning to main menu...")
- time.sleep(1)
- menu()
- ### END OF addStudent() ###
- ### SEARCH FOR A BOOK ###
- def searchStudent():
- with open('students.txt', 'r') as searchfile
- for line in searchfile:
- if 'searchphrase' in line:
- print line
- # homeinfo search
- elif criteria == 2:
- shomeinfo = input("Enter the desired homeinfo = ")
- print("Books that match your criteria")
- time.sleep(0.2)
- for line in bookDetails:
- fhomeinfo = (line.strip("")).split(",")
- # If the homeinfo in the file is equal to the homeinfo given then:
- if shomeinfo.upper() == fhomeinfo[2]:
- # Display the book details
- print("uniqueid = ",fhomeinfo[0])
- time.sleep(0.015)
- print("fullname = ",fhomeinfo[1])
- time.sleep(0.015)
- print("homeinfo = ",fhomeinfo[2])
- time.sleep(0.015)
- print("Page Count = ",fhomeinfo[3],"")
- time.sleep(0.015)
- input("Press ENTER to continue")
- menu()
- else:
- print("Wrong input given.")
- time.sleep(1.5)
- searchStudent()
- except(ValueError):
- print("Wrong input given.")
- time.sleep(1.5)
- searchStudent()
- ### END OF searchStudent() ###
- ### ADD A NEW CUSTOMER ###
- def studentDetails():
- # Open the file with student information
- f = open('students.txt', 'r')
- # Let him view file
- file_contents = f.read()# gets everything from file
- print (file_contents)# print the file
- f.close()# close the file
- # Ask Mr Leeman if he wants to add another student
- repeat = input("Would you like to see it again? (Y/N)")
- if repeat == "Y":
- studentDetails()
- elif repeat == "N":
- menu()
- else:
- print("Wrong input given. Returning to main menu...")
- time.sleep(1.5)
- menu()#return to menu
- ### END OF studentDetails() ###
- menu()
- ### END OF THE PROGRAM ###
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement