Guest User

Untitled

a guest
Oct 22nd, 2017
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1. import os
  2. import time
  3.  
  4. global goodusername
  5. global goodpassword
  6.  
  7. goodusername = 'Mr Leeman' # Username we compare against.
  8. goodpassword = 'password123' # Password we compare against.
  9. def clear():
  10. print('\n' * 100) # Simply clears the shell.
  11. def login():
  12. global goodusername
  13. global goodpassword
  14. clear()
  15. username = str(input('Please enter your username: '))
  16. password = str(input('Please enter your password: '))
  17.  
  18. if (username == goodusername) and (password == goodpassword):
  19. print('Correct combination!\n')
  20. menu()
  21. else:
  22. print('Incorrect combination! Try again!\n')
  23. login()
  24. def menu():
  25. option = int(input('What would you like to do? (1, read student data; 2, create): '))
  26. if option == 1:
  27. query()
  28. if option == 2:
  29. create()
  30. def query():
  31. try:
  32. studentid = str(input('\nPlease enter the student\'s ID number: '))
  33. student = open(('students/' + studentid + '.txt'),'r')
  34. except:
  35. print('\nAn error occured! Restarting!')
  36. time.sleep(3)
  37. login()
  38. print('\n' + str(student.read()))
  39. def create():
  40. try:
  41. studentid = str(input('\nTHIS WILL DELETE A PRE-EXISTING FILE\nPlease enter a new student ID number: '))
  42. os.remove(('students/' + studentid + '.txt')) # Deletes a students file before attempting to write a new one.
  43. except:
  44. print('File does not already exist. Proceeding.')
  45. student = open(('students/' + studentid + '.txt'), 'w')
  46.  
  47. surname = input('\nWhat is the student\'s surname?: ')
  48. forename = input('What is the student\'s forename?: ')
  49. dob = str(input('What is the student\'s date of birth? (DD/MM/YYYY): '))
  50. address = input('What is the student\'s address?: ')
  51. phonenumber = input('What is the student\'s home number?: ')
  52. gender = input('What is the student\'s gender?: ')
  53. tutor = str(input('What is the student\'s tutor group?: '))
  54. email = str(input('What is the student\'s email school address?: '))
  55.  
  56. student.write('Student ID: ' + studentid + '\n') # Writes all data collected to a file in 'students/<studentid>.txt'.
  57. student.write('Surname: ' + surname + '\n')
  58. student.write('Forename: ' + forename + '\n')
  59. student.write('Date of Birth: ' + dob + '\n')
  60. student.write('Adress: ' + address + '\n')
  61. student.write('Home phone: ' + phonenumber + '\n')
  62. student.write('Gender: ' + gender + '\n')
  63. student.write('Tutor group: ' + tutor + '\n')
  64. student.write('Email: ' + email + '\n')
  65. student.close()
  66.  
  67. print('\nFile written! Returning to menu. (3)')
  68. time.sleep(3)
  69. menu()
  70. login()
Add Comment
Please, Sign In to add comment