Advertisement
Guest User

Untitled

a guest
Oct 26th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.13 KB | None | 0 0
  1. from random import *
  2.  
  3. import json
  4.  
  5. adminStatus = False
  6.  
  7. def logreg():
  8. option = input("Do you want to(1)Login or (2)Register ? :")
  9. try:
  10. option = int(option)
  11. if option == 1:
  12. loginOption = 1
  13. return loginOption
  14. elif option == 2:
  15. loginOption = 2
  16. return loginOption
  17. else:
  18. print('=> Enter a Valid number')
  19. except ValueError:
  20. print('=> Enter a Valid number')
  21. logreg()
  22. pass
  23.  
  24. def register():
  25. print("-----Register-----")
  26.  
  27. name = input("What is your name?")
  28.  
  29. age = input("How old are you?")
  30.  
  31. yearGroup = input("What year are you in?")
  32.  
  33. username = age + name[:3]
  34.  
  35. password = input("Please enter your password?")
  36.  
  37. filename = username + ".txt"
  38.  
  39. file = {}
  40.  
  41. file['a'] = {
  42.  
  43. 'name': name,
  44.  
  45. 'age': age,
  46.  
  47. 'password': password,
  48.  
  49. 'username': username,
  50.  
  51. 'yearGroup': yearGroup,
  52.  
  53. 'admin': 0
  54.  
  55. }
  56.  
  57. s = json.dumps(file)
  58.  
  59. with open(username + ".txt", "w") as c:
  60. c.write(s)
  61.  
  62. print("-------")
  63. print("Your username is :" + username)
  64. print("Your password is :" + password)
  65. print("-------")
  66.  
  67. return True
  68. pass
  69.  
  70. def login():
  71. print("-----Login-----")
  72. username = input("Whats your username ? :")
  73. password = input("Whats your password ? :")
  74.  
  75. try:
  76. file = open(username + ".txt", "r")
  77. data = json.load(file);
  78. if password == data['a']['password']:
  79. username = data['a']['username']
  80. return username
  81. else:
  82. print("=> Wrong password")
  83. login()
  84. except FileNotFoundError:
  85. print("=> Username not found")
  86. login()
  87. pass
  88.  
  89. def topic():
  90. topic = input("Which topic (1)Maths (2)English")
  91. try:
  92. topic = int(topic)
  93. if topic == 1:
  94. return "Maths"
  95. elif topic == 2:
  96. return "English"
  97. else:
  98. print('=> Enter a Valid number')
  99. topic()
  100. except ValueError:
  101. print('=> Enter a Valid number')
  102. topic()
  103.  
  104. pass
  105.  
  106. def level():
  107. level = input("Which level (1)Easy (2)Medium (3)Hard")
  108. try:
  109. level = int(level)
  110. if level == 1:
  111. return "Easy"
  112. elif level == 2:
  113. return "Medium"
  114. elif level == 3:
  115. return "Hard"
  116. else:
  117. print('=> Enter a Valid number')
  118. level()
  119. except ValueError:
  120. print('=> Enter a Valid number')
  121. level()
  122. pass
  123.  
  124. def quizLoad():
  125. print("-----Quiz-----")
  126. choice1 = topic()
  127. choice2 = level()
  128.  
  129. quizChoice =(choice1 + choice2 + ".csv")
  130. try:
  131. file = open(choice1 + choice2 + ".csv", "r")
  132. rawData = file.readlines()
  133. file.close()
  134. except FileNotFoundError:
  135. print("Fatal Error Missing Files")
  136. quit()
  137.  
  138. return quizChoice
  139.  
  140.  
  141. def adminmenu():
  142. optionofadmin = input("Do you want to(1)Research a Name or (2)Print all results of a quiz ? :")
  143. try:
  144. optionofadmin = int(option)
  145. if optionofadmin == 1:
  146. adminname = Usernameinfile()
  147. elif optionofadmin == 2:
  148. admintopic = topic()
  149. adminlevel = level()
  150. else:
  151. print('=> Enter a Valid number')
  152. adminmenu()
  153. except ValueError:
  154. print('=> Enter a Valid number')
  155. adminmenu()
  156.  
  157. pass
  158.  
  159. loginOption = logreg()
  160.  
  161. print(loginOption)
  162.  
  163. if loginOption==1:
  164. username = login()
  165.  
  166. file = open(username + ".txt", "r")
  167. data = json.load(file);
  168.  
  169. username = data['a']['username']
  170. age = data['a']['age']
  171. password = data['a']['password']
  172. name = data['a']['name']
  173. yearGroup = data['a']['yearGroup']
  174. adminStatus = data['a']['admin']
  175. print(adminStatus)
  176. status = True
  177.  
  178. elif loginOption == 2:
  179. register()
  180. status = login()
  181.  
  182. else:
  183. print("ERROR")
  184.  
  185. while status == True:
  186. if adminStatus == "1":
  187. print("WELCOME GOD")
  188. adminmenu()
  189. else:
  190. quizLoad()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement