Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.35 KB | None | 0 0
  1. #Imports
  2. import sys
  3. import csv
  4. import time
  5. import random
  6.  
  7. #Varibles
  8. global score
  9. score = 0
  10. musicq = []
  11. computersq = []
  12. historyq = []
  13. #File Connect
  14. quiz_file = "devcheck.csv"
  15. music_config = "music.csv"
  16. computers_config = "computers.csv"
  17. history_config = "history.csv"
  18.  
  19. #Data Drag Prot.
  20. with open(music_config, 'r') as file:
  21. reader = csv.reader(file)
  22. musicq = list(reader)
  23. with open(computers_config, 'r') as file:
  24. reader = csv.reader(file)
  25. computersq = list(reader)
  26. with open(history_config, 'r') as file:
  27. reader = csv.reader(file)
  28. historyq = list(reader)
  29.  
  30. #Questions Accumulator
  31. def ComputersE( qnum ):
  32. global score
  33. C_QuE = computersq[qnum][0]
  34. print("\n",C_QuE)
  35. #print(C_QuE) #uncomment to see question
  36. CCAE = computersq[qnum][1]
  37. CIAH1 = computersq[qnum][2]
  38. rNum = random.randint(1,5)
  39. if rNum == 1:
  40. print("A:", CCAE)
  41. print("B:", CIAH1)
  42. elif rNum == 2:
  43. print("A:", CIAH1)
  44. print("B:", CCAE)
  45. elif rNum == 3:
  46. print("A:", CIAH1)
  47. print("B:", CCAE)
  48. elif rNum == 4:
  49. print("A:", CCAE)
  50. print("B:", CIAH1)
  51. elif rNum == 5:
  52. print("A:", CIAH1)
  53. print("B:", CCAE)
  54. answer = input("Please enter your answer: ")
  55. if answer.upper() == "A" and rNum == 1:
  56. print("Correct!")
  57. print("\n")
  58. score = score +1
  59. elif answer.upper() == "B" and rNum ==2:
  60. print("Correct!")
  61. print("\n")
  62. score = score +1
  63. elif answer.upper() == "C" and rNum ==3:
  64. print("Correct!")
  65. print("\n")
  66. score = score +1
  67. else:
  68. print("Incorrect!")
  69. print("\n")
  70. def ComputersM( qnum ):
  71. global score
  72. C_QuM = computersq[qnum][0]
  73. print("\n",C_QuM)
  74. #print(C_QuM) #uncomment to see question
  75. CCAM = computersq[qnum][1]
  76. CIAM1 = computersq[qnum][2]
  77. CIAM2 = computersq[qnum][3]
  78. rNum = random.randint(1,5)
  79. if rNum == 1:
  80. print("A:", CCAM)
  81. print("B:", CIAM1)
  82. print("C:", CIAM2)
  83. elif rNum == 2:
  84. print("A:", CIAM1)
  85. print("B:", CCAM)
  86. print("C:", CIAM2)
  87. elif rNum == 3:
  88. print("A:", CIAM1)
  89. print("B:", CIAM2)
  90. print("C:", CCAM)
  91. elif rNum == 4:
  92. print("A:", CIAM1)
  93. print("B:", CCAM)
  94. print("C:", CIAM2)
  95. elif rNum == 5:
  96. print("A:", CCAM)
  97. print("B:", CIAM1)
  98. print("C:", CIAM2)
  99. answer = input("Please enter your answer: ")
  100. if answer.upper() == "A" and rNum == 1:
  101. print("Correct!")
  102. print("\n")
  103. score = score +1
  104. elif answer.upper() == "B" and rNum ==2:
  105. print("Correct!")
  106. print("\n")
  107. score = score +1
  108. elif answer.upper() == "C" and rNum ==3:
  109. print("Correct!")
  110. print("\n")
  111. score = score +1
  112. else:
  113. print("Incorrect!")
  114. print("\n")
  115. def ComputersH( qnum ):
  116. global score
  117. C_QuH = computersq[qnum][0]
  118. print("\n",C_QuH)
  119. #print(C_QuH) #uncomment to see question
  120. CCAH = computersq[qnum][1]
  121. CIAH1 = computersq[qnum][2]
  122. CIAH2 = computersq[qnum][3]
  123. CIAH3 = computersq[qnum][3]
  124. rNum = random.randint(1,5)
  125. if rNum == 1:
  126. print("A:", CCAH)
  127. print("B:", CIAH1)
  128. print("C:", CIAH2)
  129. print("D:", CIAH3)
  130. elif rNum == 2:
  131. print("A:", CIAH1)
  132. print("B:", CCAH)
  133. print("C:", CIAH2)
  134. print("D:", CIAH3)
  135. elif rNum == 3:
  136. print("A:", CIAH1)
  137. print("B:", CIAH2)
  138. print("C:", CCAH)
  139. print("D:", CIAH3)
  140. elif rNum == 4:
  141. print("A:", CIAH1)
  142. print("B:", CIAH2)
  143. print("C:", CIAH3)
  144. print("D:", CCAH)
  145. elif rNum == 5:
  146. print("A:", CIAH1)
  147. print("B:", CCAH)
  148. print("C:", CIAH2)
  149. print("D:", CIAH3)
  150. answer = input("Please enter your answer: ")
  151. if answer.upper() == "A" and rNum == 1:
  152. print("Correct!")
  153. print("\n")
  154. score = score +1
  155. elif answer.upper() == "B" and rNum ==2:
  156. print("Correct!")
  157. print("\n")
  158. score = score +1
  159. elif answer.upper() == "C" and rNum ==3:
  160. print("Correct!")
  161. print("\n")
  162. score = score +1
  163. elif answer.upper() == "D" and rNum ==4:
  164. print("Correct!")
  165. print("\n")
  166. score = score +1
  167. else:
  168. print("Incorrect!")
  169. print("\n")
  170. def MusicE( qnum ):
  171. global score
  172. M_QuE = musicq[qnum][0]
  173. print("\n",M_QuE)
  174. #print(M_QuE) #uncomment to see question
  175. MCAE = musicq[qnum][1]
  176. MIAE1 = musicq[qnum][2]
  177. rNum = random.randint(1,5)
  178. if rNum == 1:
  179. print("A:", MCAE)
  180. print("B:", MIAE1)
  181. elif rNum == 2:
  182. print("A:", MIAE1)
  183. print("B:", MCAE)
  184. elif rNum == 3:
  185. print("A:", MCAE)
  186. print("B:", MIAE1)
  187. elif rNum == 4:
  188. print("A:", MIAE1)
  189. print("B:", MCAE)
  190. elif rNum == 5:
  191. print("A:", MIAE1)
  192. print("B:", MCAE)
  193. answer = input("Please enter your answer: ")
  194. if answer.upper() == "A" and rNum == 1:
  195. print("Correct!")
  196. print("\n")
  197. score = score +1
  198. elif answer.upper() == "B" and rNum ==2:
  199. print("Correct!")
  200. print("\n")
  201. score = score +1
  202. elif answer.upper() == "C" and rNum ==3:
  203. print("Correct!")
  204. print("\n")
  205. score = score +1
  206. else:
  207. print("Incorrect!")
  208. print("\n")
  209. def MusicM( qnum ):
  210. global score
  211. M_QuM = musicq[qnum][0]
  212. print("\n",M_QuM)
  213. #print(M_QuM) #uncomment to see question
  214. MCAM = musicq[qnum][1]
  215. MIAM1 = musicq[qnum][2]
  216. MIAM2 = musicq[qnum][3]
  217. rNum = random.randint(1,5)
  218. if rNum == 1:
  219. print("A:", MCAM)
  220. print("B:", MIAM2) #History Incorrect Answer Medium 1
  221. print("C:", MIAM1)
  222. elif rNum == 2:
  223. print("A:", MIAM2)
  224. print("B:", MCAM)
  225. print("C:", MIAM1)
  226. elif rNum == 3:
  227. print("A:", MIAM2)
  228. print("B:", MIAM1)
  229. print("C:", MCAM)
  230. elif rNum == 4:
  231. print("A:", MCAM)
  232. print("B:", MIAM1)
  233. print("C:", MIAM2)
  234. elif rNum == 5:
  235. print("A:", MIAM1)
  236. print("B:", MCAM)
  237. print("C:", MIAM2)
  238. answer = input("Please enter your answer: ")
  239. if answer.upper() == "A" and rNum == 1:
  240. print("Correct!")
  241. print("\n")
  242. score = score +1
  243. elif answer.upper() == "B" and rNum ==2:
  244. print("Correct!")
  245. print("\n")
  246. score = score +1
  247. elif answer.upper() == "C" and rNum ==3:
  248. print("Correct!")
  249. print("\n")
  250. score = score +1
  251. else:
  252. print("Incorrect!")
  253. print("\n")
  254. def MusicH( qnum ):
  255. global score
  256. M_QuH = musicq[qnum][0]
  257. print("\n",M_QuH)
  258. #print(M_QuH) #uncomment to see question
  259. MCAH = musicq[qnum][1]
  260. MIAH1 = musicq[qnum][2]
  261. MIAH2 = musicq[qnum][3]
  262. MIAH3 = musicq[qnum][3]
  263. rNum = random.randint(1,5)
  264. if rNum == 1:
  265. print("A:", MCAH)
  266. print("B:", MIAH1)
  267. print("C:", MIAH2)
  268. print("D:", MIAH3)
  269. elif rNum == 2:
  270. print("A:", MIAH1)
  271. print("B:", MCAH)
  272. print("C:", MIAH2)
  273. print("D:", MIAH3)
  274. elif rNum == 3:
  275. print("A:", MIAH1)
  276. print("B:", MIAH2)
  277. print("C:", MCAH)
  278. print("D:", MIAH3)
  279. elif rNum == 4:
  280. print("A:", MIAH1)
  281. print("B:", MIAH2)
  282. print("C:", MIAH3)
  283. print("D:", MCAH)
  284. elif rNum == 5:
  285. print("A:", MIAH1)
  286. print("B:", MCAH)
  287. print("C:", MIAH2)
  288. print("D:", MIAH3)
  289. answer = input("Please enter your answer: ")
  290. if answer.upper() == "A" and rNum == 1:
  291. print("Correct!")
  292. print("\n")
  293. score = score +1
  294. elif answer.upper() == "B" and rNum ==2:
  295. print("Correct!")
  296. print("\n")
  297. score = score +1
  298. elif answer.upper() == "C" and rNum ==3:
  299. print("Correct!")
  300. print("\n")
  301. score = score +1
  302. elif answer.upper() == "D" and rNum ==4:
  303. print("Correct!")
  304. print("\n")
  305. score = score +1
  306. else:
  307. print("Incorrect!")
  308. print("\n")
  309. def HistoryE( qnum ):
  310. global score
  311. H_QuE = historyq[qnum][0]
  312. print("\n",H_QuE)
  313. #print(H_QuE) #uncomment to see question
  314. HCAE = historyq[qnum][1]
  315. HIAE1 = historyq[qnum][2]
  316. rNum = random.randint(1,5)
  317. if rNum == 1:
  318. print("A:", HCAE)
  319. print("B:", HIAE1)
  320. elif rNum == 2:
  321. print("A:", HIAE1)
  322. print("B:", HCAE)
  323. elif rNum == 3:
  324. print("A:", HIAE1)
  325. print("B:", HCAE)
  326. elif rNum == 4:
  327. print("A:", HIAE1)
  328. print("B:", HCAE)
  329. elif rNum == 5:
  330. print("A:", HCAE)
  331. print("B:", HIAE1)
  332. answer = input("Please enter your answer: ")
  333. if answer.upper() == "A" and rNum == 1:
  334. print("Correct!")
  335. print("\n")
  336. score = score +1
  337. elif answer.upper() == "B" and rNum ==2:
  338. print("Correct!")
  339. print("\n")
  340. score = score +1
  341. elif answer.upper() == "C" and rNum ==3:
  342. print("Correct!")
  343. print("\n")
  344. score = score +1
  345. else:
  346. print("Incorrect!")
  347. print("\n")
  348. def HistoryM( qnum ):
  349. global score
  350. H_QuM = historyq[qnum][0]
  351. print("\n",H_QuM)
  352. #print(H_QuM) #uncomment to see question
  353. HCAM = historyq[qnum][1]
  354. HIAM1 = historyq[qnum][2]
  355. HIAM2 = historyq[qnum][3]
  356. rNum = random.randint(1,5)
  357. if rNum == 1:
  358. print("A:", HCAM)
  359. print("B:", HIAM1) #History Incorrect Answer Medium 1
  360. print("C:", HIAM2)
  361. elif rNum == 2:
  362. print("A:", HIAM1)
  363. print("B:", HCAM)
  364. print("C:", HIAM2)
  365. elif rNum == 3:
  366. print("A:", HIAM1)
  367. print("B:", HIAM2)
  368. print("C:", HCAM)
  369. elif rNum == 4:
  370. print("A:", HCAM)
  371. print("B:", HIAM2)
  372. print("C:", HIAM1)
  373. elif rNum == 5:
  374. print("A:", HIAM2)
  375. print("B:", HCAM)
  376. print("C:", HIAM1)
  377. answer = input("Please enter your answer: ")
  378. if answer.upper() == "A" and rNum == 1:
  379. print("Correct!")
  380. print("\n")
  381. score = score +1
  382. elif answer.upper() == "B" and rNum ==2:
  383. print("Correct!")
  384. print("\n")
  385. score = score +1
  386. elif answer.upper() == "C" and rNum ==3:
  387. print("Correct!")
  388. print("\n")
  389. score = score +1
  390. else:
  391. print("Incorrect!")
  392. print("\n")
  393. def HistoryH( qnum ):
  394. global score
  395. H_QuH = historyq[qnum][0]
  396. print("\n",H_QuH)
  397. #print(H_QuH) #uncomment to see question
  398. HCAH = historyq[qnum][1]
  399. HIAH1 = historyq[qnum][2]
  400. HIAH2 = historyq[qnum][3]
  401. HIAH3 = historyq[qnum][4]
  402. rNum = random.randint(1,5)
  403. if rNum == 1:
  404. print("A:", HCAH)
  405. print("B:", HIAH1)
  406. print("C:", HIAH2)
  407. print("D:", HIAH3)
  408. elif rNum == 2:
  409. print("A:", HIAH1)
  410. print("B:", HCAH)
  411. print("C:", HIAH2)
  412. print("D:", HIAH3) #History Incorrect Answer Hard 3
  413. elif rNum == 3:
  414. print("A:", HIAH1)
  415. print("B:", HIAH2)
  416. print("C:", HCAH)
  417. print("D:", HIAH3)
  418. elif rNum == 4:
  419. print("A:", HIAH1)
  420. print("B:", HIAH2)
  421. print("C:", HIAH3)
  422. print("D:", HCAH)
  423. elif rNum == 5:
  424. print("A:", HCAH)
  425. print("B:", HIAH1)
  426. print("C:", HIAH2)
  427. print("D:", HIAH3)
  428. answer = input("Please enter your answer: ")
  429. if answer.upper() == "A" and rNum == 1:
  430. print("Correct!")
  431. print("\n")
  432. score = score +1
  433. elif answer.upper() == "B" and rNum ==2:
  434. print("Correct!")
  435. print("\n")
  436. score = score +1
  437. elif answer.upper() == "C" and rNum ==3:
  438. print("Correct!")
  439. print("\n")
  440. score = score +1
  441. elif answer.upper() == "D" and rNum ==4:
  442. print("Correct!")
  443. print("\n")
  444. score = score +1
  445. else:
  446. print("Incorrect!")
  447. print("\n")
  448. def report():
  449. if score == 0:
  450. time.sleep(1)
  451. print("==== Quiz Results ====")
  452. print(" You Scored:", score)
  453. print(" Your grade is: U")
  454. print(" Percent: 0%")
  455. print("======================")
  456. print("\n")
  457. print("Thank you for playing!")
  458. elif score == 1:
  459. time.sleep(1)
  460. print("==== Quiz Results ====")
  461. print(" You Scored:", score)
  462. print(" Your grade is: D")
  463. print(" Percent: 20%")
  464. print("======================")
  465. print("\n")
  466. print("Thank you for playing!")
  467. elif score == 2:
  468. time.sleep(1)
  469. print("==== Quiz Results ====")
  470. print(" You Scored:", score)
  471. print(" Your grade is: C")
  472. print(" Percent: 40%")
  473. print("======================")
  474. print("\n")
  475. print("Thank you for playing!")
  476. elif score == 3:
  477. time.sleep(1)
  478. print("==== Quiz Results ====")
  479. print(" You Scored:", score)
  480. print(" Your grade is: B")
  481. print(" Percent: 60%")
  482. print("======================")
  483. print("\n")
  484. print("Thank you for playing!")
  485. elif score == 4:
  486. time.sleep(1)
  487. print("==== Quiz Results ====")
  488. print(" You Scored:", score)
  489. print(" Your grade is: A")
  490. print(" Percent: 80%")
  491. print("======================")
  492. print("\n")
  493. print("Thank you for playing!")
  494. elif score == 5:
  495. time.sleep(1)
  496. print("==== Quiz Results ====")
  497. print(" You Scored:", score)
  498. print(" Your grade is: A*")
  499. print(" Percent: 100%")
  500. print("======================")
  501. print("\n")
  502. print("Thank you for playing!")
  503. print("=== Main Menu ===")
  504. print(" A - Take Quiz")
  505. print(" B - Print Rep")
  506. print(" C - Exit")
  507. print("=================")
  508. usr_action = input()
  509. if usr_action.upper() == "A":
  510. print("Welcome to the Quiz! \n Create an account to start.")
  511. print("\n")
  512. time.sleep(1)
  513. print("Please enter the following infomation:")
  514. time.sleep(1)
  515. while True:
  516. try:
  517. usr_name = []
  518. usr_name = input("Name: ")
  519. if usr_name.isdigit():
  520. print('*You have entered a incorrect value!* \n *Make sure you enter only text!*')
  521. print("\n")
  522. else:
  523. break
  524. except ValueError:
  525. print("ERROR! ErrorCode: GS01") #error code here
  526. while True:
  527. try:
  528. usr_age = input("Age: ")
  529. if usr_age.isdigit(): #checks if its a number
  530. break
  531. else:
  532. print('*You have entered a incorrect value!* \n *Make sure you enter only numerical values here!*')
  533. print("\n")
  534. except ValueError:
  535. print("ERROR! ErrorCode: GS02") #error code here
  536. while True:
  537. try:
  538. usr_yrgrp = input("Year Group:")
  539. if usr_yrgrp.isdigit(): #checks if its a number
  540. break
  541. else:
  542. print('*You have entered a incorrect value!* \n *Make sure you enter only numerical values here!*')
  543. print("\n")
  544. except ValueError:
  545. print("ERROR! ErrorCode: GS03")
  546. global usr_username #error code here
  547. usr_username = usr_name[0] + usr_name[1] + usr_name[2] + str(usr_age)
  548. print("\n")
  549. print("Your username is: ",usr_username)
  550. time.sleep(0.9)
  551. usr_password = input("Please create a password: ") ## FIX ME PLEASE
  552. while True:
  553. try:
  554. usr_password_re = input("Please retype your password: ")
  555. print("\n")
  556. if usr_password == usr_password_re:
  557. time.sleep(1)
  558. break
  559. else:
  560. print("Password doesn't match! retype password")
  561. except ValueError:
  562. print("ERROR! ErrorCode: GS04") #error codes here!
  563. print("Account created! \n Welcome", usr_username)
  564. print("\n")
  565. def writeFile():
  566. myFile = open('users.txt','a')
  567. myFile.write("=== User Info ===")
  568. myFile.write("\n")
  569. myFile.write("Name: ")
  570. myFile.write(usr_name)
  571. myFile.write("\n")
  572. myFile.write("Age: ")
  573. myFile.write(usr_age)
  574. myFile.write("\n")
  575. myFile.write("Age Group: ")
  576. myFile.write(usr_yrgrp)
  577. myFile.write("\n")
  578. myFile.write("Username: ")
  579. myFile.write(usr_username)
  580. myFile.write("\n")
  581. myFile.write("Password: ")
  582. myFile.write(usr_password)
  583. myFile.write("\n")
  584. myFile.write("Topic: ")
  585. myFile.write(usr_actop)
  586. myFile.write("\n")
  587. myFile.write("Difficulty: ")
  588. myFile.write(usr_acdiff)
  589. myFile.write("\n")
  590. myFile.write("Score: ")
  591. myFile.write(str(score))
  592. myFile.write("\n")
  593. myFile.close()
  594. print("===== Topic =====")
  595. print(" A - Computers")
  596. print(" B - History")
  597. print(" C - Music")
  598. print("=================")
  599. usr_actop = input()
  600. time.sleep(1)
  601. if usr_actop.upper() == "A":
  602. usr_actop = "Computers"
  603. print("==== Difficulty ====")
  604. print(" A - Easy")
  605. print(" B - Medium")
  606. print(" C - Hard")
  607. print("====================")
  608. usr_acdiff = input()
  609. time.sleep(1)
  610. if usr_acdiff.upper() == "A":
  611. usr_acdiff = "Easy"
  612. for counter in range(5):
  613. ComputersE(counter)
  614. report()
  615. writeFile()
  616. elif usr_acdiff.upper() == "B":
  617. usr_acdiff = "Medium"
  618. for counter in range(5):
  619. ComputersM(counter)
  620. report()
  621. writeFile()
  622. elif usr_acdiff.upper() == "C":
  623. usr_acdiff = "Hard"
  624. for counter in range(5):
  625. ComputersH(counter)
  626. report()
  627. writeFile()
  628. elif usr_actop.upper() == "B":
  629. usr_actop = "History"
  630. print("==== Difficulty ====")
  631. print(" A - Easy")
  632. print(" B - Medium")
  633. print(" C - Hard")
  634. print("====================")
  635. usr_acdiff = input()
  636. time.sleep(1)
  637. if usr_acdiff.upper() == "A":
  638. usr_acdiff = "Easy"
  639. for counter in range(5):
  640. HistoryE(counter)
  641. report()
  642. writeFile()
  643. elif usr_acdiff.upper() == "B":
  644. usr_acdiff = "Medium"
  645. for counter in range(5):
  646. HistoryM(counter)
  647. report()
  648. writeFile()
  649. elif usr_acdiff.upper() == "C":
  650. usr_acdiff = "Hard"
  651. for counter in range(5):
  652. HistoryH(counter)
  653. report()
  654. writeFile()
  655. elif usr_actop.upper() == "C":
  656. usr_actop = "Music"
  657. print("==== Difficulty ====")
  658. print(" A - Easy")
  659. print(" B - Medium")
  660. print(" C - Hard")
  661. print("====================")
  662. usr_acdiff = input()
  663. time.sleep(1)
  664. if usr_acdiff.upper() == "A":
  665. usr_acdiff = "Easy"
  666. for counter in range(5):
  667. MusicE(counter)
  668. report()
  669. writeFile()
  670. elif usr_acdiff.upper() == "B":
  671. usr_acdiff = "Medium"
  672. for counter in range(5):
  673. MusicM(counter)
  674. report()
  675. writeFile()
  676. elif usr_acdiff.upper() == "C":
  677. usr_acdiff = "Hard"
  678. for counter in range(5):
  679. MusicH(counter)
  680. report()
  681. writeFile()
  682.  
  683. elif usr_action.upper() == "B":
  684. print("Print REP HERE!")
  685.  
  686. elif usr_action.upper() == "C":
  687. print("Exiting Program")
  688. time.sleep(0.5)
  689. print("Saving Data...")
  690. time.sleep(0.5)
  691. print("Exit")
  692. sys.exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement