In this task you'll be creating another search feature with a report for your teacher. Suppose he needs to regularly email all the males in his tutor group with a reminder for boys football trials. Create a search feature and report that lists all the males in the file with their corresponding email addresses
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 import time import sys 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() #open the file with open('studentfile.txt','a') as studentfile: #create a studentfile Writer - enables us to perform 'write' operations studentfileWriter=csv.writer(studentfile) #use the studenfile Writer to write all the variables entered to the file (as as a row) studentfileWriter.writerow([id,firstname,surname,dob,firstlineaddress,postcode,gender,tutorgroup,email]) print("Record has been written to file") studentfile.close() #Return to main menu for further options or to quit the program 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("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() #the program is initiated, so to speak, here main()
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 |