Guest User

Untitled

a guest
Nov 21st, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.15 KB | None | 0 0
  1. def quiz():
  2. print ("quiz")# place holder for real code (let's me know the function has been run)
  3. def report():
  4. print ("report") # place holder for real code (let's me know the function has been run)
  5. def a_menu():# Admin menu
  6. print ("Welcome to the student quiz!")
  7. print ("Please choose a option")
  8. while True:
  9. print ("1: Computer science")
  10. print ("2: Histroy")
  11. print ("3: Reports")
  12. menu_in = int(input())
  13. if menu_in == 1:
  14. Comp_sci = True
  15. quiz()
  16. break
  17. elif menu_in == 2:
  18. Hist = True
  19. quiz()
  20. break
  21. elif menu_in == 3:
  22. report()
  23. break
  24. else:
  25. print ("Invalid input! Please try again..")
  26. def menu():
  27. print ("Welcome to the student quiz!")
  28. print ("Please choose a quiz")
  29. while True:
  30.  
  31. print ("1: Computer science")
  32. print ("2: Histroy")
  33. menu_in = int(input())
  34. if menu_in == 1:
  35. Comp_sci = True
  36. quiz()
  37. break
  38. elif menu_in == 2:
  39. Hist = True
  40. quiz()
  41. break
  42. def login():
  43. b = False
  44. print ("Please enter your username and password")
  45. while True:
  46. if b == True:
  47. break
  48. log_user = input("Username:")
  49. log_pass = input ("Password:")
  50. with open("D:\Computer science\Computing test\logindata.txt","r") as log_read:
  51. num_lines = sum(1 for line in open('D:\Computer science\Computing test\logindata.txt'))
  52. num_lines = num_lines-1
  53. for line in log_read:
  54. log_line = log_read.readline()
  55. log_splt = log_line.split(",")
  56. if log_user == log_splt[0] and log_pass == log_splt[2]:
  57. if log_splt[5] == "a": # Admin will have to mannually change the admin status of other user's through .txt file.
  58. b = True
  59. a_menu()
  60. else:
  61. b = True
  62. log_read.close()
  63. menu()
  64. break
  65. else:
  66. print ("Incorrect username or password, please try again!")
  67. def register():
  68. print ("enter your name, age, and year group and password")
  69. while True:
  70. reg_name = input("Name:")
  71. reg_pass = input ("Password:")
  72. reg_age = input ("age:")
  73. reg_group = input ("Year Group:")
  74. print ("Is this infomation correct?")
  75. print ("Name:",reg_name)
  76. print ("password:",reg_pass)
  77. print ("Age:",reg_age)
  78. print ("Year Group:", reg_group)
  79. reg_correct = input ("[Y/N]").lower()
  80. if reg_correct == "y":
  81. reg_user = reg_name[0:3]+reg_age
  82. reg_write = open("D:\Computer science\Computing test\logindata.txt","a")
  83. reg_write.write (reg_user+","+reg_name+","+reg_pass+","+reg_age+","+reg_group+","+"u"+"n")
  84. print ("Your username is:",reg_user)
  85. reg_write.close()
  86. login()
  87. break
  88. elif reg_correct == "n":
  89. print ("Please Re-enter your infomation")
  90. else:
  91. Print ("Invalid input! Please try again...!")
  92. def login_ask():
  93. print ("Do you already have an account?")
  94. while True:
  95. ask_in = input("[Y/N]").lower()
  96. if ask_in == "y":
  97. login()
  98. break
  99. elif ask_in == "n":
  100. register()
  101. break
  102. login_ask()
Add Comment
Please, Sign In to add comment