Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.70 KB | None | 0 0
  1. def Trivia():
  2. score = 0
  3. print("maths")
  4. print("science")
  5. Quiz = raw_input("Pick a Subject(Please type in no caps):")
  6. QuizFile = open(Quiz+".txt","r") # opens the CSV file and stores it in the array myFile
  7. lines = QuizFile.readlines() # reads the lines of the CSV file into the variable players
  8. QuestionNO=1
  9. print("Choose your Difficutly:")
  10. print("1.Easy")
  11. print("2.Medium")
  12. print("3.Hard")
  13. Difficultychoice = int(raw_input("Enter a choice(1-3)"))
  14. if Difficultychoice == 1:
  15. QuizFile = open(Quiz+".txt","r") # opens the CSV file and stores it in the array myFile
  16. lines = QuizFile.readlines() # reads the lines of the CSV file into the variable players
  17. QuestionNO=1
  18.  
  19. for details in lines:
  20. data = details.split(",") #splits each cell of the CSV file into its part
  21. questions = data[0]
  22. answera = data[1] #These 6 codes assigns the individual data in the text file to variables
  23. answerb = data[4] #
  24. correctanswer = data[5]
  25. print(correctanswer)
  26. print("Question #",QuestionNO)
  27. print(questions) #prints the question and the 4 answers
  28. print("1. " +answera) #
  29. print("2. " +answerb) #
  30. A1= raw_input("Input Your Answer(Make sure you enter a full answer):")#asks the user for their answer
  31. print(".")
  32. print(".")
  33. print(".")
  34. if A1 == correctanswer: #checks if the answer is correct and prints approptiate responses
  35. print("That is the correct answer")
  36. score=score+1 #adds a point to your ovwerall score everytime you get the answer right
  37. else:
  38. print("That is not the correct answer.(Make sure you enter the full answer)")
  39. print("Your current score is", score)
  40. print("")
  41.  
  42. QuestionNO = QuestionNO+1 #this adds 1 to the variable QuestionNO, this is to loop the whole code till thwe variable questionNO is 10
  43. QuizFile.close()
  44. elif Difficultychoice == 2:
  45. QuizFile = open(Quiz+".txt","r") # opens the CSV file and stores it in the array myFile
  46. lines = QuizFile.readlines() # reads the lines of the CSV file into the variable players
  47. QuestionNO=1
  48.  
  49. for details in lines:
  50. data = details.split(",") #splits each cell of the CSV file into its part
  51. questions = data[0]
  52. answera = data[1] #These 6 codes assigns the individual data in the text file to variables
  53. answerb = data[2] #
  54. answerc = data[4] #
  55. correctanswer = data[5]
  56. print(correctanswer)
  57. print("Question #",QuestionNO)
  58. print(questions) #prints the question and the 4 answers
  59. print("1. " +answerb) #
  60. print("2. " +answera) #
  61. print("3. " +answerc) #
  62. A1= raw_input("Input Your Answer(Make sure you enter a full answer):")#asks the user for their answer
  63. print(".")
  64. print(".")
  65. print(".")
  66. if A1 == correctanswer: #checks if the answer is correct and prints approptiate responses
  67. print("That is the correct answer")
  68. score=score+1 #adds a point to your ovwerall score everytime you get the answer right
  69. else:
  70. print("That is not the correct answer.(Make sure you enter the full answer)")
  71. print("Your current score is", score)
  72. print("")
  73.  
  74. QuestionNO = QuestionNO+1 #this adds 1 to the variable QuestionNO, this is to loop the whole code till thwe variable questionNO is 10
  75. QuizFile.close()
  76. elif Difficultychoice == 3:
  77. QuizFile = open(Quiz+".txt","r") # opens the CSV file and stores it in the array myFile
  78. lines = QuizFile.readlines() # reads the lines of the CSV file into the variable players
  79. QuestionNO=1
  80.  
  81. for details in lines:
  82. data = details.split(",") #splits each cell of the CSV file into its part
  83. questions = data[0]
  84. answera = data[1] #These 6 codes assigns the individual data in the text file to variables
  85. answerb = data[2] #
  86. answerc = data[3] #
  87. answerd = data[4] #
  88. correctanswer = data[5]
  89. print(correctanswer)
  90. print("Question #",QuestionNO)
  91. print(questions) #prints the question and the 4 answers
  92. print("1. " +answera) #
  93. print("2. " +answerb) #
  94. print("3. " +answerc) #
  95. print("4. " +answerd) #
  96. A1= raw_input("Input Your Answer(Make sure you enter a full answer):")#asks the user for their answer
  97. print(".")
  98. print(".")
  99. print(".")
  100. if A1 == correctanswer: #checks if the answer is correct and prints approptiate responses
  101. print("That is the correct answer")
  102. score=score+1 #adds a point to your ovwerall score everytime you get the answer right
  103. else:
  104. print("That is not the correct answer.(Make sure you enter the full answer)")
  105. print("Your current score is", score)
  106. print("")
  107.  
  108. QuestionNO = QuestionNO+1 #this adds 1 to the variable QuestionNO, this is to loop the whole code till thwe variable questionNO is 10
  109. QuizFile.close()
  110. print()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement