Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import statistics as s #To create maths qs. like mean, median etc.. and allows me to write statistic as s to decrease typing time
- import random #random letters to add to a name (to make it unique), also random questions
- import string
- import sys #system/ sys.end to end the program
- import time
- import json
- def adlogin():#This is the function responsible for the login of the admin
- print("Please enter the administrator's username")
- def stlogin():#This is the function responsible for the login of students
- print ("you have chosen to login")
- with open("file.txt") as read:
- username = input("Username:")
- try:
- data = json.load(read)
- except ValueError:
- print("no users registered. Sign up!!!")
- try:
- data = json.load(read)
- except json.decoder.JSONDecodeError as je:
- print('invalid json: %s' % je)
- print ("no users registered. Sign up!!!")
- time.sleep(1)
- entrance()
- data = json.load(read)
- inputted_user = input("username")
- if inputted_user in open('file.txt').read():
- if type(inputted_user) == str:
- account = json.loads(inputted_user)
- inputted_password = input(" Password: ")
- if inputted_password == account["password"]:
- print("logged in")
- else:
- print("incorrect login")
- else:
- print("incorrect login")
- else:
- print("incorrect login")
- def signup():
- print ("you have chosen to sign up.")
- name = input("Please enter your name.\n {Name}: ")
- nameforinfo = name
- age = input("Please enter your age:\n[This program is optimised for those 11-17]\n{age}: ")
- while int(age) < 10 or int(age) > 18:# loop created until a valid age entered.
- age = input("What is your age?\n{age}: ")
- username = (name[0:3] + age)
- while username in open('userinfo.txt').read():#checking the availability of username
- username += random.choice(string.ascii_letters)
- print ("your username is " + username)
- password = input("Make a password (longer than 5 letters).\n{password}:")
- while len(password) < 3:
- print("password is too short")
- password = input("Make a password (longer than 5 letters).\n{password}:")
- userinfo = open("userinfo.txt", 'w')
- userinfo.write("User's Info\n")
- userinfo.close()
- with open("userinfo.txt", 'w') as w:
- w.write(
- json.dumps(
- {
- "user": {
- "username": username,
- "name": nameforinfo,
- "age" : age,
- "password": password
- }
- }
- )
- )
- entrance()
- def close():#This is the function which quits the program.
- closebinary =input("Are you sure you want to quit? {yes} {no}\n{yes/no}: ")
- if closebinary == "yes":
- print("See you next time")
- time.sleep(2)
- sys.exit
- elif closebinary == "no":
- print("Glad you're staying with us.")
- time.sleep(2)
- entrance()
- else:
- invalid_answer()
- def invalid_answer():
- print("Thats not a valid answer.\nI'll prompt you to the start.")
- time.sleep(2)
- entrance()
- def entrance():
- print("Hello and welcome to this quiz")
- answer = input("{1} Student Login\n{2}Admin Login:\n{3}Signup\n{4}Exit\n{#}: ")
- if answer == "1":
- stlogin()
- elif answer == "2" :
- adlogin()
- elif answer == "3" :
- signup()
- elif answer == "4" :
- close()
- else:
- invalid_answer()
- entrance()
- entrance()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement