~ Repprt #2 Search by Gender (females) with email addresses returned.


Sample Project - Form Tutor Management System

*Teachers with subscriptions will have access to all worked solutions and python code. This sample project is based on OCR GCSE NEA Task 1

CHALLENGE: 

Here you will be creating a similar report to the one you just did! Think of more interesting ones if you can, else just do this example. Produce a report of all the females in the file with their email address. Your teacher, let's say, needs to tell them about a coding club for girls only that has been started by a local company!

SUGGESTED SOLUTION / CODE: 

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

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()

Analyse

Write your own summary of the problem. What are your objectives? List the success criteria

Design Tools

Designing something or writing out some pseudocode before you actually write code is always a good idea! Get in to the habit of doing so! You can draw your flowchart here and screenshot it.

Try it yourself

Testing Table

You may want to read a little about Testing first. A teacher may go through some examples with you. Feel free to fill in the test table here, and screenshot it in to your powerpoint. Testing is absolutely essential once you have created a program!
Test No. Description Test Data(input) Expected Outcome Actual Outcome Further Action?
1
2
3
4
5
Coming soon!