Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os,sys,inspect,base64,sys
- from time import sleep
- if not os.path.exists("install"):
- os.mkdir("install")
- quizz = """import os,sys,inspect,base64,sys
- from time import sleep
- debug = False
- 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(""+"0");
- usr.write(""+"0");
- usr.close();
- main(user);
- if debug == True:
- save("kostek")
- a = 1
- while a == 1:
- os.system("cls")
- print("Welcome to the QuizzWould you like to Register or Login?")
- 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)
- """
- add = """import os,sys,inspect,base64,sys
- from time import sleep
- if os.path.exists("install"):
- sys.exit(101001)
- 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"
- while True:
- am = 0
- os.system("cls")
- name = input("Name of the question set (EXIT to Quit): ")
- os.system("cls")
- for root, dirs, files in os.walk("."):
- for filename in files:
- if filename == name+".dat":
- am = am + 1
- if am == 1:
- print("Files with the name provided have been found, choose a different name!")
- sleep(0.6)
- if name.lower() == "exit":
- sys.exit(1)
- if name.lower() != "reload" and am == 0 or None:
- qnr = input("Number of questions for this set: ")
- os.chdir(config)
- with open(name+".dat","w") as conf:
- conf.write(qnr+"")
- l = input("Maximum amount of points possible to score: ")
- conf.write(l+"")
- conf.close()
- for i in range(0,int(qnr)):
- i += 1
- 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"
- os.system("cls")
- os.chdir(quiz)
- with open(name+".dat","a+") as qu:
- a = input(str(i)+". Question: ")
- if i != int(qnr):
- qu.write(a+"")
- else:
- qu.write(a)
- qu.close()
- os.chdir(ref)
- with open(name+".dat","a+") as ref:
- b = input("Question list for "+str(i)+". Question (A: Answer B: Answer C: Answer or more): ")
- if i != int(qnr):
- ref.write(b+"")
- else:
- ref.write(b)
- os.chdir(answers)
- with open(name+".dat","a+") as ans:
- c = input("Correct answer for "+str(i)+". Question (A or B or C or more): ")
- if i != int(qnr):
- ans.write(c+"")
- else:
- ans.write(c)
- os.chdir(config)
- with open(name+".dat","a+") as conf:
- d = input("Amount of points for "+str(i)+". Question: ")
- if i != int(qnr):
- conf.write(d+"")
- else:
- conf.write(d)
- print("You have successfully created a Question Set named: ",name)
- else:
- print("This name is prohibited!")
- """
- if not os.path.exists("Quizz.py"):
- with open("Quizz.py","w") as a1:
- a1.write(quizz)
- if not os.path.exists("Add_Module.py"):
- with open("Add_Module.py","w") as a2:
- a2.write(add)
- sleep(2)
- os.startfile("Quizz.py")
- os.startfile("Add_Module.py")
- sleep(3)
- os.removedirs("install")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement