Below, is the full solution. Remember, this is by no means a perfect solution. It just solves the problem in a very basic way and there is now plenty for you to discuss.
Testing the full solution is crucial. Make sure you test all parts of the program with all the relevant types of test data to ensure it really does work. You should have also kept a test log as you went along, keeping track of what worked, and what didn't and what you changed and solved along the way! This is also called a developmental log. It's important so that people know the work is your own!
There are many little niggles with the current solution. Not everything is as perfect as it could be. Here are a few things you could discuss (and add to your EVALUATION)
1. What could you improve about this solution?
2. What validation has been considered? Where could more validation be considered and added?
3. Are there other reports you think would be more useful?
4. Could the formatting of the reports be better?
5. Can you think of any flaws that could occur in the registration screen/registration feature
6. How could you further improve the login feature. What if an intruder was repeatedly trying to login as the teacher ...?
Note: See if you can do better (and you should be able to). The solutions provided are basic, and allow for discussion on possible alternative methods and solutions.
#Form Tutor Management System import csv #this allows you to work with the CSV file reader/writer etc. import sys #this allows you to use (in this case) the sys.exit command which allows quit/logout #improvements to consider: #a) Validation considerations (for input to file in particular) #b) Automatic generation of ID and Email? #c) Upload of CSV file, if necessary #d) Further Validation for input of fields (in reports) def main(): login() def login(): #declare variables. Enter data for username and password username="qwe" password="qwe123" #Prompt the user to enter their username and password print("Enter username : ") answer1=input() print("Enter password : ") answer2=input() #if the responses for username and password equal the declarations, access granted if answer1==username and answer2==password: print("Welcome - Access Granted") menu() def menu(): print("************MAIN MENU**************") #time.sleep(1) print() #print all the menu options: choice = input(""" A: Enter Student details B: View Student details C: Search by ID number D: Produce Reports Q: Quit/Log Out Please enter your choice: """) #if the choice is A,B,C, D or Q, go to the corresponding subroutine if choice == "A" or choice =="a": enterstudentdetails() elif choice == "B" or choice =="b": viewstudentdetails() elif choice == "C" or choice =="c": searchbyid() elif choice=="D" or choice=="d": producereports() elif choice=="Q" or choice=="q": sys.exit else: #error checking - if they put in nonsense, make sure they know what to do! print("You must only select either A,B,C, or D.") print("Please try again") #Return to main menu for further options or to quit the program menu() def enterstudentdetails(): #user is prompted to input all the required fields print("Enter id") id=input() print("Enter first name") firstname=input() print("Enter surname") surname=input() print("Enter Date of Birth Format: dd/mm/yy") dob=input() print("Enter first line of address") firstlineaddress=input() print("Enter Postcode") postcode=input() print("Enter Gender") gender=input() print("Enter Tutor Group") tutorgroup=input() print("Enter email address") email=input() with open('studentfile.txt','a') as studentfile: studentfileWriter=csv.writer(studentfile) studentfileWriter.writerow([id,firstname,surname,dob,firstlineaddress,postcode,gender,tutorgroup,email]) print("Record has been written to file") studentfile.close() menu() def viewstudentdetails(): #Open the file for reading f=open("studentfile.txt","r",encoding="utf8") #Create a list called "displaylist" into which all the files lines are read in to.... displaylist=f.read() #print the list (that now has the file details in it) print(displaylist) f.close() menu() def searchbyid(): #open the file as student file (variable) with open("studentfile.txt","r") as studentfile: #prompt the user to enter the ID number they require idnumber=input("Enter the ID number you require:") #call upon our reader (this allows us to work with our file) studentfileReader=csv.reader(studentfile) #for each row that is read by the Reader for row in studentfileReader: #and for each field in that row (this does it automatically for us) for field in row: #if the field is equal to the id number that is being searched for if field ==idnumber: #print the row corresponding to that ID number print(row) #Return to main menu for further options or to quit the program menu() def producereports(): print("************PRODUCE REPORTS**************") #time.sleep(1) print() #print all the menu options: choice = input(""" A: View all student details *for General use B: List of Males + Email *For Football club trials C: List of Females + Email *For Female clubs D: Search by D.O.B + Address *For Birthday cards Q: Quit/Log Out Please enter your choice: """) #if the choice is A,B,C, D or Q, go to the corresponding subroutine if choice == "A" or choice =="a": viewstudentdetails() elif choice == "B" or choice =="b": malesandemail() elif choice == "C" or choice =="c": femalesandemail() elif choice=="D" or choice=="d": dobandaddress() elif choice=="Q" or choice=="q": sys.exit else: #error checking - if they put in nonsense, make sure they know what to do! print("You must only select either A,B,C, or D.") print("Please try again") #Return to main menu for further options or to quit the program menu() def dobandaddress(): #open the file as student file with open("studentfile.txt","r") as studentfile: #prompt the user to enter today's date print("*********Don't forget someone's Birthday!*******") dob=input("Enter today's date:") #call upon our reader (this allows us to work with our file) studentfileReader=csv.reader(studentfile) #for each row that is read by the Reader for row in studentfileReader: #and for each field in that row (this does it automatically for us) for field in row: #if the field is equal to the id number that is being searched for #if field==dob: (this would search for the whole date of birth in the field) if dob in field: #this looks for the entered dob (even a part of it, in the field) - not a perfect solution. How could it be further improved? #print the row corresponding to that ID number print("Searching file ....please wait") print("Send a card to:", row) #Return to main menu for further options or to quit the program pressenter = input("Press 'm' to return to Main Menu: >>") if pressenter=="m": menu() else: dobandaddress() def malesandemail(): #open the file as student file gender = "Male" with open("studentfile.txt","r") as studentfile: print("*********List of Male students + Emails: Boys Football trials reminder*******") #call upon our reader (this allows us to work with our file) studentfileReader=csv.reader(studentfile) #for each row that is read by the Reader for row in studentfileReader: #and for each field in that row (this does it automatically for us) for field in row: #if the field is equal to the id number that is being searched for if field==gender: #print the row corresponding to that ID number print(row[1],row[2], "...Email address:", row[8]) #Return to main menu for further options or to quit the program pressenter = input("Press 'm' to return to Main Menu: >>") if pressenter=="m": menu() def femalesandemail(): #open the file as student file gender = "Female" with open("studentfile.txt","r") as studentfile: print("*********List of Female students + Emails: Girls club email reminder*******") #call upon our reader (this allows us to work with our file) studentfileReader=csv.reader(studentfile) #for each row that is read by the Reader for row in studentfileReader: #and for each field in that row (this does it automatically for us) for field in row: #if the field is equal to the id number that is being searched for if field==gender: #print the row corresponding to that ID number print(row[1],row[2], "...Email address:", row[8]) #Return to main menu for further options or to quit the program pressenter = input("Press 'm' to return to Main Menu: >>") if pressenter=="m": menu() #the program is initiated, so to speak, here main()
Did you make a list of objectives and success criteria when you started this task? Tick them off and write a sentence next to each explaining how you did/or did not solve it
The problem could be broken down into the following sub-problems. We are going to solve (or try to) each one:
1. Create a Login Screen
2. Create a Main Menu and define all the functions/sub programs needed in the program
3. Create a registration feature (need to save this to a file)
4. View all Student details (read from file)
5. Create a "Search by ID" feature
6. Create a "Produce Reports" feature
7. Search by Birthday (OR DOB) or Address feature (this is a report)
8. Create a report for Males and their emails
9. Create a report for all Females and their emails
10. Final Solution - reflect! How could you improve it? Test it!
Write your own summary of the problem. What are your objectives? List the success criteria
Test No. | Description | Test Data(input) | Expected Outcome | Actual Outcome | Further Action? |
---|---|---|---|---|---|
1 | |||||
2 | |||||
3 | |||||
4 | |||||
5 |