Advertisement
nadiachoudhry123

NEA 1 code

Aug 25th, 2016
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.65 KB | None | 0 0
  1. import csv
  2. import os
  3.  
  4. def login():
  5.  
  6.     userName = ""
  7.     passWord= ""
  8.     correctPassword = "HELLO"
  9.     correctUsername = "NADIA"
  10.     while userName != correctUsername and passWord != correctPassword:
  11.    
  12.         userName=str(input("Please enter your username:  ")).upper()
  13.  
  14.         passWord=str(input("Please enter password")).upper()
  15.  
  16.         if userName == correctUsername and passWord == correctPassword:
  17.                      print("You may enter")
  18.         if userName != correctUsername and passWord != correctPassword:
  19.             print("sorry, you can not enter")
  20.            
  21.  
  22. #login()
  23.  
  24. def menu():
  25.     choice = ""
  26.     exit1 = "4"
  27.     print("1. Enter new student details")
  28.     print("2. Dispay student details")
  29.     print("3. Create a report")
  30.     print("4. Exit menu")
  31.  
  32.     while choice != exit1:
  33.         choice = str(input("What menu choice would you like?"))
  34.        
  35.         if choice == exit1:
  36.             break
  37.  
  38. #menu()
  39.  
  40.  
  41. def menuReport():
  42.     choice = ""
  43.     exit1 = "4"
  44.     print("1. Student Form Report")
  45.     print("2. Student Email Report")
  46.     print("3. Student Gender Report")
  47.     print("4. Exit menu")
  48.  
  49.     while choice != exit1:
  50.         choice = str(input("What menu choice would you like?"))
  51.         if choice == "1":
  52.             file=open("report1.txt","r")
  53.             allfilecontents=file.read()
  54.             print(allfilecontents)
  55.             print("...running Student Full Report")
  56.         if choice == "2":
  57.             file=open("report2.txt","r")
  58.             allfilecontents=file.read()
  59.             print(allfilecontents)
  60.             print("...running Student Email Report")
  61.         if choice == "3":
  62.             file=open("report3.txt","r")
  63.             allfilecontents=file.read()
  64.             print(allfilecontents)
  65.             print("...running Student Form Report")
  66.            
  67.         if choice == exit1:
  68.             break
  69.        
  70.  
  71. #menuReport()
  72.  
  73.  
  74.  
  75.    
  76. def studentData():
  77.  
  78.     fileName = "students.csv"
  79.     accessMode ="a"
  80.  
  81.     ID = int(input("Enter ID number:1000"))
  82.     surname = input("Enter surname")
  83.     forename = input("Enter forename")
  84.     DOB = input("Enter DOB as 00/00/0000")
  85.     address=input("Enter address")
  86.     telephone=input("enter telephone number")
  87.     gender = input("Enter gender: m or f")
  88.     formclass=input("Enter form class: ")
  89.     email = forename + surname +"@treeroad.sch.uk"
  90.  
  91.  
  92.     with open(fileName,accessMode) as student:
  93.         studentDetailsWriter = csv.writer(student)
  94.         studentDetailsWriter.writerow([ID,surname,forename,DOB,address,telephone,gender,formclass,email])      
  95.     student.close()
  96.     print("file written successfully")
  97.  
  98. #studentData()
  99.  
  100.  
  101.  
  102. def extractData():
  103.     with open("students.csv") as csvfile:
  104.         readCSV = csv.reader(csvfile, delimiter = ",")
  105.        
  106.  
  107.         studentID =[]
  108.         lastName = []
  109.         firstName =[]
  110.         DOB = []
  111.         address = []
  112.         telephone = []
  113.         gender =[]
  114.         form = []
  115.         email = []
  116.        
  117.         for row in readCSV:
  118.             studentIDs=row[0]
  119.             lastNames=row[1]
  120.             firstNames=row[2]
  121.             DOBs=row[3]
  122.             addresss=row[4]
  123.             telephones=row[5]
  124.             genders=row[6]
  125.             forms=row[7]
  126.             emails=row[8]
  127.  
  128.         #print(studentID)
  129.         #print(lastName)
  130.            
  131.             studentID.append(studentIDs)
  132.             lastName.append(lastNames)
  133.             firstName.append(firstNames)
  134.             DOB.append(DOBs)
  135.             address.append(addresss)
  136.             telephone.append(telephones)
  137.             gender.append(genders)
  138.             form.append(forms)
  139.             email.append(emails)
  140.  
  141.     ##    print(studentID)
  142.     ##    print(lastName)
  143.     ##    print(firstName)
  144.         whatStudentID = ""
  145.  
  146.     while whatStudentID != studentID:    
  147.         whatStudentID = input("Please enter the student id: ")
  148.  
  149.         studind = studentID.index(whatStudentID)
  150.  
  151.         thelastName = lastName[studind]
  152.         thefirstName=firstName[studind]
  153.         theDOB=DOB[studind]
  154.         theAddress = address[studind]
  155.         theTelephone = telephone [studind]
  156.         theGender = gender[studind]
  157.         theForm = form[studind]
  158.         theEmails =email[studind]
  159.        
  160.        
  161.        
  162.        
  163.         print("Student ID:",whatStudentID)
  164.         print("Last Name: ",thelastName)
  165.         print("First Name: ", thefirstName)
  166.         print("DOB:", theDOB)
  167.         print("Address: ", theAddress)
  168.         print("Telephone: ",theTelephone)
  169.         print("Gender: ",theGender)
  170.         print("Form: ", theForm)
  171.         print("Email: ",theEmails)
  172.  
  173.    
  174.         if whatStudentID == studind:
  175.              break
  176.  
  177. #extractData()
  178.  
  179.  
  180. def report1():
  181.  
  182.     ifile = 'C:/Users/Nadia/Documents/NEA Project 2/students.csv'
  183.     ofile = 'C:/Users/Nadia/Documents/NEA Project 2/report1.txt'
  184.     with open(ifile, 'r') as read_file, open(ofile, 'w') as write_file:
  185.         csvreader = csv.reader(read_file, delimiter=',', quotechar='"')
  186.         csvwriter = csv.writer(write_file, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
  187.         for row in csvreader:
  188.                 csvwriter.writerow(row)
  189.  
  190. #report1()
  191.  
  192. def report2():
  193.  
  194.     ifile = 'C:/Users/Nadia/Documents/NEA Project 2/students.csv'
  195.     ofile = 'C:/Users/Nadia/Documents/NEA Project 2/report2.txt'
  196.  
  197.     with open(ifile, 'r') as read_file, open(ofile, 'w', newline='') as write_file:
  198.         csvreader = csv.reader(read_file, delimiter=',', quotechar='"')
  199.         csvwriter = csv.writer(write_file, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
  200.         for row in csvreader:
  201.                 foo = list()
  202.                 foo.append(str(row[0]).rstrip())
  203.                 foo.append(str(row[8]).rstrip())
  204.                 csvwriter.writerow(foo)
  205. #report2()
  206.  
  207. def report3():
  208.  
  209.  
  210.     ifile = 'C:/Users/Nadia/Documents/NEA Project 2/students.csv'
  211.     ofile = 'C:/Users/Nadia/Documents/NEA Project 2/report3.txt'
  212.  
  213.     with open(ifile, 'r') as read_file, open(ofile, 'w', newline='') as write_file:
  214.         csvreader = csv.reader(read_file, delimiter=',', quotechar='"')
  215.         csvwriter = csv.writer(write_file, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
  216.         for row in csvreader:
  217.                 foo = list()
  218.                 foo.append(str(row[0]).rstrip())
  219.                 foo.append(str(row[1]).rstrip())
  220.                 foo.append(str(row[2]).rstrip())
  221.                 foo.append(str(row[7]).rstrip())
  222.                 csvwriter.writerow(foo)
  223.  
  224. #report3()
  225.            
  226.  
  227.  
  228. print("Welcome to the school menu system")
  229. print("Please log in below")
  230.  
  231.  
  232. login()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement