Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import time
- global goodusername
- global goodpassword
- goodusername = 'Mr Leeman' # Username we compare against.
- goodpassword = 'password123' # Password we compare against.
- def clear():
- print('\n' * 100) # Simply clears the shell.
- def login():
- global goodusername
- global goodpassword
- clear()
- username = str(input('Please enter your username: '))
- password = str(input('Please enter your password: '))
- if (username == goodusername) and (password == goodpassword):
- print('Correct combination!\n')
- menu()
- else:
- print('Incorrect combination! Try again!\n')
- login()
- def menu():
- option = int(input('What would you like to do? (1, read student data; 2, create): '))
- if option == 1:
- query()
- if option == 2:
- create()
- def query():
- try:
- studentid = str(input('\nPlease enter the student\'s ID number: '))
- student = open(('students/' + studentid + '.txt'),'r')
- except:
- print('\nAn error occured! Restarting!')
- time.sleep(3)
- login()
- print('\n' + str(student.read()))
- def create():
- try:
- studentid = str(input('\nTHIS WILL DELETE A PRE-EXISTING FILE\nPlease enter a new student ID number: '))
- os.remove(('students/' + studentid + '.txt')) # Deletes a students file before attempting to write a new one.
- except:
- print('File does not already exist. Proceeding.')
- student = open(('students/' + studentid + '.txt'), 'w')
- surname = input('\nWhat is the student\'s surname?: ')
- forename = input('What is the student\'s forename?: ')
- dob = str(input('What is the student\'s date of birth? (DD/MM/YYYY): '))
- address = input('What is the student\'s address?: ')
- phonenumber = input('What is the student\'s home number?: ')
- gender = input('What is the student\'s gender?: ')
- tutor = str(input('What is the student\'s tutor group?: '))
- email = str(input('What is the student\'s email school address?: '))
- student.write('Student ID: ' + studentid + '\n') # Writes all data collected to a file in 'students/<studentid>.txt'.
- student.write('Surname: ' + surname + '\n')
- student.write('Forename: ' + forename + '\n')
- student.write('Date of Birth: ' + dob + '\n')
- student.write('Adress: ' + address + '\n')
- student.write('Home phone: ' + phonenumber + '\n')
- student.write('Gender: ' + gender + '\n')
- student.write('Tutor group: ' + tutor + '\n')
- student.write('Email: ' + email + '\n')
- student.close()
- print('\nFile written! Returning to menu. (3)')
- time.sleep(3)
- menu()
- login()
Add Comment
Please, Sign In to add comment