Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import csv
- import os
- def login():
- userName = ""
- passWord= ""
- correctPassword = "HELLO"
- correctUsername = "NADIA"
- while userName != correctUsername and passWord != correctPassword:
- userName=str(input("Please enter your username: ")).upper()
- passWord=str(input("Please enter password")).upper()
- if userName == correctUsername and passWord == correctPassword:
- print("You may enter")
- if userName != correctUsername and passWord != correctPassword:
- print("sorry, you can not enter")
- #login()
- def menu():
- choice = ""
- exit1 = "4"
- print("1. Enter new student details")
- print("2. Dispay student details")
- print("3. Create a report")
- print("4. Exit menu")
- while choice != exit1:
- choice = str(input("What menu choice would you like?"))
- if choice == exit1:
- break
- #menu()
- def menuReport():
- choice = ""
- exit1 = "4"
- print("1. Student Form Report")
- print("2. Student Email Report")
- print("3. Student Gender Report")
- print("4. Exit menu")
- while choice != exit1:
- choice = str(input("What menu choice would you like?"))
- if choice == "1":
- file=open("report1.txt","r")
- allfilecontents=file.read()
- print(allfilecontents)
- print("...running Student Full Report")
- if choice == "2":
- file=open("report2.txt","r")
- allfilecontents=file.read()
- print(allfilecontents)
- print("...running Student Email Report")
- if choice == "3":
- file=open("report3.txt","r")
- allfilecontents=file.read()
- print(allfilecontents)
- print("...running Student Form Report")
- if choice == exit1:
- break
- #menuReport()
- def studentData():
- fileName = "students.csv"
- accessMode ="a"
- ID = int(input("Enter ID number:1000"))
- surname = input("Enter surname")
- forename = input("Enter forename")
- DOB = input("Enter DOB as 00/00/0000")
- address=input("Enter address")
- telephone=input("enter telephone number")
- gender = input("Enter gender: m or f")
- formclass=input("Enter form class: ")
- email = forename + surname +"@treeroad.sch.uk"
- with open(fileName,accessMode) as student:
- studentDetailsWriter = csv.writer(student)
- studentDetailsWriter.writerow([ID,surname,forename,DOB,address,telephone,gender,formclass,email])
- student.close()
- print("file written successfully")
- #studentData()
- def extractData():
- with open("students.csv") as csvfile:
- readCSV = csv.reader(csvfile, delimiter = ",")
- studentID =[]
- lastName = []
- firstName =[]
- DOB = []
- address = []
- telephone = []
- gender =[]
- form = []
- email = []
- for row in readCSV:
- studentIDs=row[0]
- lastNames=row[1]
- firstNames=row[2]
- DOBs=row[3]
- addresss=row[4]
- telephones=row[5]
- genders=row[6]
- forms=row[7]
- emails=row[8]
- #print(studentID)
- #print(lastName)
- studentID.append(studentIDs)
- lastName.append(lastNames)
- firstName.append(firstNames)
- DOB.append(DOBs)
- address.append(addresss)
- telephone.append(telephones)
- gender.append(genders)
- form.append(forms)
- email.append(emails)
- ## print(studentID)
- ## print(lastName)
- ## print(firstName)
- whatStudentID = ""
- while whatStudentID != studentID:
- whatStudentID = input("Please enter the student id: ")
- studind = studentID.index(whatStudentID)
- thelastName = lastName[studind]
- thefirstName=firstName[studind]
- theDOB=DOB[studind]
- theAddress = address[studind]
- theTelephone = telephone [studind]
- theGender = gender[studind]
- theForm = form[studind]
- theEmails =email[studind]
- print("Student ID:",whatStudentID)
- print("Last Name: ",thelastName)
- print("First Name: ", thefirstName)
- print("DOB:", theDOB)
- print("Address: ", theAddress)
- print("Telephone: ",theTelephone)
- print("Gender: ",theGender)
- print("Form: ", theForm)
- print("Email: ",theEmails)
- if whatStudentID == studind:
- break
- #extractData()
- def report1():
- ifile = 'C:/Users/Nadia/Documents/NEA Project 2/students.csv'
- ofile = 'C:/Users/Nadia/Documents/NEA Project 2/report1.txt'
- with open(ifile, 'r') as read_file, open(ofile, 'w') as write_file:
- csvreader = csv.reader(read_file, delimiter=',', quotechar='"')
- csvwriter = csv.writer(write_file, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
- for row in csvreader:
- csvwriter.writerow(row)
- #report1()
- def report2():
- ifile = 'C:/Users/Nadia/Documents/NEA Project 2/students.csv'
- ofile = 'C:/Users/Nadia/Documents/NEA Project 2/report2.txt'
- with open(ifile, 'r') as read_file, open(ofile, 'w', newline='') as write_file:
- csvreader = csv.reader(read_file, delimiter=',', quotechar='"')
- csvwriter = csv.writer(write_file, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
- for row in csvreader:
- foo = list()
- foo.append(str(row[0]).rstrip())
- foo.append(str(row[8]).rstrip())
- csvwriter.writerow(foo)
- #report2()
- def report3():
- ifile = 'C:/Users/Nadia/Documents/NEA Project 2/students.csv'
- ofile = 'C:/Users/Nadia/Documents/NEA Project 2/report3.txt'
- with open(ifile, 'r') as read_file, open(ofile, 'w', newline='') as write_file:
- csvreader = csv.reader(read_file, delimiter=',', quotechar='"')
- csvwriter = csv.writer(write_file, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
- for row in csvreader:
- foo = list()
- foo.append(str(row[0]).rstrip())
- foo.append(str(row[1]).rstrip())
- foo.append(str(row[2]).rstrip())
- foo.append(str(row[7]).rstrip())
- csvwriter.writerow(foo)
- #report3()
- print("Welcome to the school menu system")
- print("Please log in below")
- login()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement