Advertisement
Guest User

Untitled

a guest
Jun 2nd, 2018
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.63 KB | None | 0 0
  1. import os,sys,inspect,base64,sys
  2. from time import sleep
  3.  
  4. for root, dirs, files in os.walk("."):
  5. for filename in files:
  6. if filename == "Quizz.py":
  7. os.system("title "+filename.replace(".py",""))
  8.  
  9. mdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
  10. data = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))+"/Data"
  11. quiz = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))+"/Core/Questions"
  12. ref = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))+"/Core/Reference"
  13. answers = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))+"/Core/Answers"
  14. config = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))+"/Core/Config"
  15.  
  16. if inspect.getfile(inspect.currentframe()) != inspect.getfile(inspect.currentframe()):
  17. while True:
  18. os.system("cls")
  19. print("File currupted.");
  20. input()
  21.  
  22. if not os.path.exists("Core"):
  23. os.mkdir("Core")
  24.  
  25. os.chdir("Core")
  26. if not os.path.exists("Questions"):
  27. os.mkdir("Questions")
  28.  
  29. if not os.path.exists("Answers"):
  30. os.mkdir("Answers")
  31.  
  32. if not os.path.exists("Config"):
  33. os.mkdir("Config")
  34.  
  35. if not os.path.exists("Reference"):
  36. os.mkdir("Reference")
  37.  
  38. os.chdir(mdir)
  39. if not os.path.exists("Data"):
  40. os.mkdir("Data")
  41.  
  42. if os.path.exists("install"):
  43. sys.exit(101001)
  44.  
  45. attempts = 0;
  46. cur_test_score = 0;
  47. cur_test_max_score = 0;
  48. cur_test_question = 0;
  49. nr_ref = 0;
  50. max_score = 0;
  51. score = 0;
  52. os.chdir(config);
  53. for root, dirs, files in os.walk("."):
  54. for filename in files:
  55. with open(filename,"r+") as k:
  56. max_score += int(k.readlines()[1]);
  57.  
  58. def question(qset):
  59. global cur_test_question
  60. global cur_test_max_score
  61. global cur_test_score
  62. os.chdir(quiz)
  63. with open(qset+".dat","r") as kek:
  64. lop = kek.readlines()
  65. kek.close()
  66. os.chdir(ref)
  67. with open(qset+".dat","r") as kek:
  68. lpo = kek.readlines()
  69. kek.close()
  70. print("",lop[0+cur_test_question],"",lpo[0+cur_test_question])
  71. cur_test_question += 1
  72.  
  73.  
  74. def answer(qset,ans):
  75. global nr_ref
  76. global cur_test_max_score
  77. global cur_test_score
  78. os.chdir(answers)
  79. with open(qset+".dat","r") as kek:
  80. lop = kek.readlines()
  81. kek.close()
  82. if ans == lop[0+nr_ref].replace("",""):
  83. os.chdir(config)
  84. with open(qset+".dat","r") as kek:
  85. con = kek.readlines()
  86. kek.close()
  87. cur_test_score += int(con[2+nr_ref])
  88. return("Correct")
  89. else:
  90. return("Incorrect")
  91.  
  92. def quizz(user,qset):
  93. global cur_test_question
  94. global cur_test_max_score
  95. global cur_test_score
  96. global nr_ref
  97. global attempts
  98. os.chdir(quiz);
  99. with open(qset+".dat") as q:
  100. qs = q.readlines();
  101. os.chdir(config);
  102. with open(qset+".dat") as conf:
  103. con = conf.readlines();
  104. os.system("cls");
  105. for i in range(0,int(con[0])):
  106. os.system("cls")
  107. 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)
  108. question(qset)
  109. ans = input("Choose your answer: ").upper()
  110. os.system("cls")
  111. print(answer(qset,ans))
  112. nr_ref += 1
  113. sleep(1.2)
  114. os.system("cls")
  115. per = cur_test_score / int(con[1]) * 100
  116. print("You have completed the test! Your score for this test was "+str(cur_test_score)+"/"+str(con[1])+"That is "+str(per)+"%")
  117. input()
  118. save(user)
  119.  
  120. def save(user):
  121. global cur_test_score
  122. global attempts
  123. os.chdir(data)
  124. with open(base64.b64encode(str.encode(user)).decode()+".dat","r+") as lel:
  125. content = lel.readlines()
  126. lel.close()
  127. add1 = int(content[1]) + cur_test_score
  128. add2 = int(content[2]) + attempts
  129. content[1] = str(add1)+""
  130. content[2] = str(add2)
  131. with open(base64.b64encode(str.encode(user)).decode()+".dat","w") as lol:
  132. for line in content:
  133. lol.write(str(line))
  134. main(user)
  135.  
  136. def main(user):
  137. global score
  138. global attempts
  139. global cur_test_question
  140. global cur_test_max_score
  141. global cur_test_score
  142. global nr_ref
  143. os.chdir(data)
  144. with open(base64.b64encode(str.encode(user)).decode()+".dat","r+") as usr:
  145. content = usr.readlines()
  146. points = content[1]
  147. attempts = int(content[2])
  148. cur_test_score = 0;
  149. cur_test_max_score = 0;
  150. cur_test_question = 0;
  151. nr_ref = 0;
  152. score = 0;
  153. while True:
  154. os.system("cls");
  155. print("Your points:",points,"Your overall test attempts:",attempts,"");
  156. print("Available Quizzes:");
  157. os.chdir(quiz);
  158. quizzes = []
  159. for root, dirs, files in os.walk("."):
  160. for filename in files:
  161. quizzes.append(filename.replace(".dat",""));
  162. print(filename.replace(".dat",""));
  163. ch = input("What test would you like to try? ");
  164. if ch == "reload":
  165. print("Reloading...")
  166. sleep(0.5)
  167. elif ch in quizzes:
  168. quizz(user,ch)
  169. else:
  170. os.system("cls")
  171. print("The question set does not exist!")
  172. sleep(2)
  173.  
  174.  
  175. def Log(msg,err):
  176. os.system("cls");
  177. if err == None:
  178. print(msg);
  179. if err == 1:
  180. print("Password or Username does not match!");
  181. if err == 2:
  182. print("Invalid input!");
  183. if err == 3:
  184. print("Unknown error, Code: 3");
  185. sleep(2);
  186.  
  187. def login(user,password):
  188. os.chdir(data)
  189. if not os.path.exists(base64.b64encode(str.encode(user)).decode()+".dat"):
  190. Log("",1);
  191. else:
  192. with open(base64.b64encode(str.encode(user)).decode()+".dat","r") as usr:
  193. content = usr.readlines()
  194. if content[0].replace("","") == base64.b64encode(str.encode(password)).decode():
  195. Log("You have successfully logged in",None);
  196. main(user);
  197. else:
  198. Log("",1);
  199.  
  200. def register(user,password,c_password):
  201. os.chdir(data)
  202. if c_password != password:
  203. Log("Passwords do not match!",None)
  204. elif user == password:
  205. Log("Username cannot be the same as passwords",None);
  206. elif len(password) < 8:
  207. Log("Password is too short",None)
  208. elif len(password) > 24:
  209. Log("Password is too long",None)
  210. else:
  211. if not os.path.exists(base64.b64encode(str.encode(user)).decode()+".dat"):
  212. with open(base64.b64encode(str.encode(user)).decode()+".dat","w+") as usr:
  213. usr.write(base64.b64encode(str.encode(password)).decode());
  214. usr.write("\n"+"0");
  215. usr.write("\n"+"0");
  216. usr.close();
  217. main(user);
  218.  
  219. a = 1
  220. while a == 1:
  221. os.system("cls")
  222. print("Welcome to the Quizz\nWould you like to Register or Login?\n")
  223. c = input("").lower()
  224. check = c
  225. if c == "register" or c == "reg" or c == "r":
  226. while c == check:
  227. os.system("cls")
  228. username = input("Your username: ")
  229. password = input("Your password: ")
  230. c_password = input("Confirm your password: ")
  231. a = 0
  232. register(username,password,c_password)
  233. elif c == "login" or c == "log" or c == "l":
  234. while c == check:
  235. os.system("cls")
  236. username = input("Username: ")
  237. password = input("Password: ")
  238. a = 0
  239. login(username,password)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement