Advertisement
Guest User

Untitled

a guest
Jun 2nd, 2018
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.25 KB | None | 0 0
  1. import os,sys,inspect,base64,sys
  2. from time import sleep
  3.  
  4. if not os.path.exists("install"):
  5. os.mkdir("install")
  6. quizz = """import os,sys,inspect,base64,sys
  7. from time import sleep
  8.  
  9. debug = False
  10.  
  11. for root, dirs, files in os.walk("."):
  12. for filename in files:
  13. if filename == "Quizz.py":
  14. os.system("title "+filename.replace(".py",""))
  15.  
  16. mdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
  17. data = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))+"/Data"
  18. quiz = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))+"/Core/Questions"
  19. ref = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))+"/Core/Reference"
  20. answers = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))+"/Core/Answers"
  21. config = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))+"/Core/Config"
  22.  
  23. if inspect.getfile(inspect.currentframe()) != inspect.getfile(inspect.currentframe()):
  24. while True:
  25. os.system("cls")
  26. print("File currupted.");
  27. input()
  28.  
  29. if not os.path.exists("Core"):
  30. os.mkdir("Core")
  31.  
  32. os.chdir("Core")
  33. if not os.path.exists("Questions"):
  34. os.mkdir("Questions")
  35.  
  36. if not os.path.exists("Answers"):
  37. os.mkdir("Answers")
  38.  
  39. if not os.path.exists("Config"):
  40. os.mkdir("Config")
  41.  
  42. if not os.path.exists("Reference"):
  43. os.mkdir("Reference")
  44.  
  45. os.chdir(mdir)
  46. if not os.path.exists("Data"):
  47. os.mkdir("Data")
  48.  
  49. if os.path.exists("install"):
  50. sys.exit(101001)
  51.  
  52. attempts = 0;
  53. cur_test_score = 0;
  54. cur_test_max_score = 0;
  55. cur_test_question = 0;
  56. nr_ref = 0;
  57. max_score = 0;
  58. score = 0;
  59. os.chdir(config);
  60. for root, dirs, files in os.walk("."):
  61. for filename in files:
  62. with open(filename,"r+") as k:
  63. max_score += int(k.readlines()[1]);
  64.  
  65. def question(qset):
  66. global cur_test_question
  67. global cur_test_max_score
  68. global cur_test_score
  69. os.chdir(quiz)
  70. with open(qset+".dat","r") as kek:
  71. lop = kek.readlines()
  72. kek.close()
  73. os.chdir(ref)
  74. with open(qset+".dat","r") as kek:
  75. lpo = kek.readlines()
  76. kek.close()
  77. print("",lop[0+cur_test_question],"",lpo[0+cur_test_question])
  78. cur_test_question += 1
  79.  
  80.  
  81. def answer(qset,ans):
  82. global nr_ref
  83. global cur_test_max_score
  84. global cur_test_score
  85. os.chdir(answers)
  86. with open(qset+".dat","r") as kek:
  87. lop = kek.readlines()
  88. kek.close()
  89. if ans == lop[0+nr_ref].replace("",""):
  90. os.chdir(config)
  91. with open(qset+".dat","r") as kek:
  92. con = kek.readlines()
  93. kek.close()
  94. cur_test_score += int(con[2+nr_ref])
  95. return("Correct")
  96. else:
  97. return("Incorrect")
  98.  
  99. def quizz(user,qset):
  100. global cur_test_question
  101. global cur_test_max_score
  102. global cur_test_score
  103. global nr_ref
  104. global attempts
  105. os.chdir(quiz);
  106. with open(qset+".dat") as q:
  107. qs = q.readlines();
  108. os.chdir(config);
  109. with open(qset+".dat") as conf:
  110. con = conf.readlines();
  111. os.system("cls");
  112. for i in range(0,int(con[0])):
  113. os.system("cls")
  114. 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)
  115. question(qset)
  116. ans = input("Choose your answer: ").upper()
  117. os.system("cls")
  118. print(answer(qset,ans))
  119. nr_ref += 1
  120. sleep(1.2)
  121. os.system("cls")
  122. per = cur_test_score / int(con[1]) * 100
  123. print("You have completed the test! Your score for this test was "+str(cur_test_score)+"/"+str(con[1])+"That is "+str(per)+"%")
  124. input()
  125. save(user)
  126.  
  127. def save(user):
  128. global cur_test_score
  129. global attempts
  130. os.chdir(data)
  131. with open(base64.b64encode(str.encode(user)).decode()+".dat","r+") as lel:
  132. content = lel.readlines()
  133. lel.close()
  134. add1 = int(content[1]) + cur_test_score
  135. add2 = int(content[2]) + attempts
  136. content[1] = str(add1)+""
  137. content[2] = str(add2)
  138. with open(base64.b64encode(str.encode(user)).decode()+".dat","w") as lol:
  139. for line in content:
  140. lol.write(str(line))
  141. main(user)
  142.  
  143. def main(user):
  144. global score
  145. global attempts
  146. global cur_test_question
  147. global cur_test_max_score
  148. global cur_test_score
  149. global nr_ref
  150. os.chdir(data)
  151. with open(base64.b64encode(str.encode(user)).decode()+".dat","r+") as usr:
  152. content = usr.readlines()
  153. points = content[1]
  154. attempts = int(content[2])
  155. cur_test_score = 0;
  156. cur_test_max_score = 0;
  157. cur_test_question = 0;
  158. nr_ref = 0;
  159. score = 0;
  160. while True:
  161. os.system("cls");
  162. print("Your points:",points,"Your overall test attempts:",attempts,"");
  163. print("Available Quizzes:");
  164. os.chdir(quiz);
  165. quizzes = []
  166. for root, dirs, files in os.walk("."):
  167. for filename in files:
  168. quizzes.append(filename.replace(".dat",""));
  169. print(filename.replace(".dat",""));
  170. ch = input("What test would you like to try? ");
  171. if ch == "reload":
  172. print("Reloading...")
  173. sleep(0.5)
  174. elif ch in quizzes:
  175. quizz(user,ch)
  176. else:
  177. os.system("cls")
  178. print("The question set does not exist!")
  179. sleep(2)
  180.  
  181.  
  182. def Log(msg,err):
  183. os.system("cls");
  184. if err == None:
  185. print(msg);
  186. if err == 1:
  187. print("Password or Username does not match!");
  188. if err == 2:
  189. print("Invalid input!");
  190. if err == 3:
  191. print("Unknown error, Code: 3");
  192. sleep(2);
  193.  
  194. def login(user,password):
  195. os.chdir(data)
  196. if not os.path.exists(base64.b64encode(str.encode(user)).decode()+".dat"):
  197. Log("",1);
  198. else:
  199. with open(base64.b64encode(str.encode(user)).decode()+".dat","r") as usr:
  200. content = usr.readlines()
  201. if content[0].replace("","") == base64.b64encode(str.encode(password)).decode():
  202. Log("You have successfully logged in",None);
  203. main(user);
  204. else:
  205. Log("",1);
  206.  
  207. def register(user,password,c_password):
  208. os.chdir(data)
  209. if c_password != password:
  210. Log("Passwords do not match!",None)
  211. elif user == password:
  212. Log("Username cannot be the same as passwords",None);
  213. elif len(password) < 8:
  214. Log("Password is too short",None)
  215. elif len(password) > 24:
  216. Log("Password is too long",None)
  217. else:
  218. if not os.path.exists(base64.b64encode(str.encode(user)).decode()+".dat"):
  219. with open(base64.b64encode(str.encode(user)).decode()+".dat","w+") as usr:
  220. usr.write(base64.b64encode(str.encode(password)).decode());
  221. usr.write(""+"0");
  222. usr.write(""+"0");
  223. usr.close();
  224. main(user);
  225.  
  226. if debug == True:
  227. save("kostek")
  228.  
  229. a = 1
  230. while a == 1:
  231. os.system("cls")
  232. print("Welcome to the QuizzWould you like to Register or Login?")
  233. c = input("").lower()
  234. check = c
  235. if c == "register" or c == "reg" or c == "r":
  236. while c == check:
  237. os.system("cls")
  238. username = input("Your username: ")
  239. password = input("Your password: ")
  240. c_password = input("Confirm your password: ")
  241. a = 0
  242. register(username,password,c_password)
  243. elif c == "login" or c == "log" or c == "l":
  244. while c == check:
  245. os.system("cls")
  246. username = input("Username: ")
  247. password = input("Password: ")
  248. a = 0
  249. login(username,password)
  250. """
  251. add = """import os,sys,inspect,base64,sys
  252. from time import sleep
  253.  
  254. if os.path.exists("install"):
  255. sys.exit(101001)
  256.  
  257. quiz = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))+"/Core/Questions"
  258. ref = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))+"/Core/Reference"
  259. answers = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))+"/Core/Answers"
  260. config = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))+"/Core/Config"
  261.  
  262. while True:
  263. am = 0
  264. os.system("cls")
  265. name = input("Name of the question set (EXIT to Quit): ")
  266. os.system("cls")
  267. for root, dirs, files in os.walk("."):
  268. for filename in files:
  269. if filename == name+".dat":
  270. am = am + 1
  271. if am == 1:
  272. print("Files with the name provided have been found, choose a different name!")
  273. sleep(0.6)
  274. if name.lower() == "exit":
  275. sys.exit(1)
  276. if name.lower() != "reload" and am == 0 or None:
  277. qnr = input("Number of questions for this set: ")
  278. os.chdir(config)
  279. with open(name+".dat","w") as conf:
  280. conf.write(qnr+"")
  281. l = input("Maximum amount of points possible to score: ")
  282. conf.write(l+"")
  283. conf.close()
  284. for i in range(0,int(qnr)):
  285. i += 1
  286. quiz = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))+"/Core/Questions"
  287. ref = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))+"/Core/Reference"
  288. answers = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))+"/Core/Answers"
  289. config = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))+"/Core/Config"
  290. os.system("cls")
  291. os.chdir(quiz)
  292. with open(name+".dat","a+") as qu:
  293. a = input(str(i)+". Question: ")
  294. if i != int(qnr):
  295. qu.write(a+"")
  296. else:
  297. qu.write(a)
  298. qu.close()
  299. os.chdir(ref)
  300. with open(name+".dat","a+") as ref:
  301. b = input("Question list for "+str(i)+". Question (A: Answer B: Answer C: Answer or more): ")
  302. if i != int(qnr):
  303. ref.write(b+"")
  304. else:
  305. ref.write(b)
  306. os.chdir(answers)
  307. with open(name+".dat","a+") as ans:
  308. c = input("Correct answer for "+str(i)+". Question (A or B or C or more): ")
  309. if i != int(qnr):
  310. ans.write(c+"")
  311. else:
  312. ans.write(c)
  313. os.chdir(config)
  314. with open(name+".dat","a+") as conf:
  315. d = input("Amount of points for "+str(i)+". Question: ")
  316. if i != int(qnr):
  317. conf.write(d+"")
  318. else:
  319. conf.write(d)
  320. print("You have successfully created a Question Set named: ",name)
  321. else:
  322. print("This name is prohibited!")
  323. """
  324. if not os.path.exists("Quizz.py"):
  325. with open("Quizz.py","w") as a1:
  326. a1.write(quizz)
  327. if not os.path.exists("Add_Module.py"):
  328. with open("Add_Module.py","w") as a2:
  329. a2.write(add)
  330. sleep(2)
  331. os.startfile("Quizz.py")
  332. os.startfile("Add_Module.py")
  333. sleep(3)
  334. os.removedirs("install")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement