Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os,sys,inspect,base64,sys
- from time import sleep
- for root, dirs, files in os.walk("."):
- for filename in files:
- if filename == "Quizz.py":
- os.system("title "+filename.replace(".py",""))
- mdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
- data = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))+"/Data"
- quiz = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))+"/Core/Questions"
- ref = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))+"/Core/Reference"
- answers = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))+"/Core/Answers"
- config = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))+"/Core/Config"
- if inspect.getfile(inspect.currentframe()) != inspect.getfile(inspect.currentframe()):
- while True:
- os.system("cls")
- print("File currupted.");
- input()
- if not os.path.exists("Core"):
- os.mkdir("Core")
- os.chdir("Core")
- if not os.path.exists("Questions"):
- os.mkdir("Questions")
- if not os.path.exists("Answers"):
- os.mkdir("Answers")
- if not os.path.exists("Config"):
- os.mkdir("Config")
- if not os.path.exists("Reference"):
- os.mkdir("Reference")
- os.chdir(mdir)
- if not os.path.exists("Data"):
- os.mkdir("Data")
- if os.path.exists("install"):
- sys.exit(101001)
- attempts = 0;
- cur_test_score = 0;
- cur_test_max_score = 0;
- cur_test_question = 0;
- nr_ref = 0;
- max_score = 0;
- score = 0;
- os.chdir(config);
- for root, dirs, files in os.walk("."):
- for filename in files:
- with open(filename,"r+") as k:
- max_score += int(k.readlines()[1]);
- def question(qset):
- global cur_test_question
- global cur_test_max_score
- global cur_test_score
- os.chdir(quiz)
- with open(qset+".dat","r") as kek:
- lop = kek.readlines()
- kek.close()
- os.chdir(ref)
- with open(qset+".dat","r") as kek:
- lpo = kek.readlines()
- kek.close()
- print("",lop[0+cur_test_question],"",lpo[0+cur_test_question])
- cur_test_question += 1
- def answer(qset,ans):
- global nr_ref
- global cur_test_max_score
- global cur_test_score
- os.chdir(answers)
- with open(qset+".dat","r") as kek:
- lop = kek.readlines()
- kek.close()
- if ans == lop[0+nr_ref].replace("",""):
- os.chdir(config)
- with open(qset+".dat","r") as kek:
- con = kek.readlines()
- kek.close()
- cur_test_score += int(con[2+nr_ref])
- return("Correct")
- else:
- return("Incorrect")
- def quizz(user,qset):
- global cur_test_question
- global cur_test_max_score
- global cur_test_score
- global nr_ref
- global attempts
- os.chdir(quiz);
- with open(qset+".dat") as q:
- qs = q.readlines();
- os.chdir(config);
- with open(qset+".dat") as conf:
- con = conf.readlines();
- os.system("cls");
- for i in range(0,int(con[0])):
- os.system("cls")
- print("This is a question set for",qset,"Number of questions in this set left:",int(con[0]) - nr_ref,"Maximum score for this set is:",con[1],"Your current score for this test is",cur_test_score,"Current question number:",cur_test_question)
- question(qset)
- ans = input("Choose your answer: ").upper()
- os.system("cls")
- print(answer(qset,ans))
- nr_ref += 1
- sleep(1.2)
- os.system("cls")
- per = cur_test_score / int(con[1]) * 100
- print("You have completed the test! Your score for this test was "+str(cur_test_score)+"/"+str(con[1])+"That is "+str(per)+"%")
- input()
- save(user)
- def save(user):
- global cur_test_score
- global attempts
- os.chdir(data)
- with open(base64.b64encode(str.encode(user)).decode()+".dat","r+") as lel:
- content = lel.readlines()
- lel.close()
- add1 = int(content[1]) + cur_test_score
- add2 = int(content[2]) + attempts
- content[1] = str(add1)+""
- content[2] = str(add2)
- with open(base64.b64encode(str.encode(user)).decode()+".dat","w") as lol:
- for line in content:
- lol.write(str(line))
- main(user)
- def main(user):
- global score
- global attempts
- global cur_test_question
- global cur_test_max_score
- global cur_test_score
- global nr_ref
- os.chdir(data)
- with open(base64.b64encode(str.encode(user)).decode()+".dat","r+") as usr:
- content = usr.readlines()
- points = content[1]
- attempts = int(content[2])
- cur_test_score = 0;
- cur_test_max_score = 0;
- cur_test_question = 0;
- nr_ref = 0;
- score = 0;
- while True:
- os.system("cls");
- print("Your points:",points,"Your overall test attempts:",attempts,"");
- print("Available Quizzes:");
- os.chdir(quiz);
- quizzes = []
- for root, dirs, files in os.walk("."):
- for filename in files:
- quizzes.append(filename.replace(".dat",""));
- print(filename.replace(".dat",""));
- ch = input("What test would you like to try? ");
- if ch == "reload":
- print("Reloading...")
- sleep(0.5)
- elif ch in quizzes:
- quizz(user,ch)
- else:
- os.system("cls")
- print("The question set does not exist!")
- sleep(2)
- def Log(msg,err):
- os.system("cls");
- if err == None:
- print(msg);
- if err == 1:
- print("Password or Username does not match!");
- if err == 2:
- print("Invalid input!");
- if err == 3:
- print("Unknown error, Code: 3");
- sleep(2);
- def login(user,password):
- os.chdir(data)
- if not os.path.exists(base64.b64encode(str.encode(user)).decode()+".dat"):
- Log("",1);
- else:
- with open(base64.b64encode(str.encode(user)).decode()+".dat","r") as usr:
- content = usr.readlines()
- if content[0].replace("","") == base64.b64encode(str.encode(password)).decode():
- Log("You have successfully logged in",None);
- main(user);
- else:
- Log("",1);
- def register(user,password,c_password):
- os.chdir(data)
- if c_password != password:
- Log("Passwords do not match!",None)
- elif user == password:
- Log("Username cannot be the same as passwords",None);
- elif len(password) < 8:
- Log("Password is too short",None)
- elif len(password) > 24:
- Log("Password is too long",None)
- else:
- if not os.path.exists(base64.b64encode(str.encode(user)).decode()+".dat"):
- with open(base64.b64encode(str.encode(user)).decode()+".dat","w+") as usr:
- usr.write(base64.b64encode(str.encode(password)).decode());
- usr.write("\n"+"0");
- usr.write("\n"+"0");
- usr.close();
- main(user);
- a = 1
- while a == 1:
- os.system("cls")
- print("Welcome to the Quizz\nWould you like to Register or Login?\n")
- c = input("").lower()
- check = c
- if c == "register" or c == "reg" or c == "r":
- while c == check:
- os.system("cls")
- username = input("Your username: ")
- password = input("Your password: ")
- c_password = input("Confirm your password: ")
- a = 0
- register(username,password,c_password)
- elif c == "login" or c == "log" or c == "l":
- while c == check:
- os.system("cls")
- username = input("Username: ")
- password = input("Password: ")
- a = 0
- login(username,password)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement