Advertisement
Guest User

Here you go

a guest
Feb 27th, 2014
656
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.95 KB | None | 0 0
  1. import csv
  2. que = 0 #So here I am setting 4 variables, the question-number, the answer-number, the hint-number and the score
  3. anw = 0
  4. hnt = 0
  5. score = 0
  6. print("Welcome, to the Data Challenge!")
  7. print("You will be asked a series of questions.")
  8. print("All correct answers will give you 2 points, while all incorrect answers will take off 1 point")
  9. print("The test is case sensitive, so add capital letters where appropriate (begginning of words)")
  10. print("If you need help, type 'Hint' as your answer, and a tip will come up")
  11. print("However, this will cost you 1 point")
  12. print()
  13. print("Remember, this test is Case Sensitive, so do not miss out on those captials.")
  14. print()
  15. begin = str(input("Are you ready to begin? (Y/N)  "))
  16. print()
  17. if begin == "Y":
  18.     print("Lets do this!")
  19.     qes = True #the variable qes here is just used for a while loop
  20.     while qes:
  21.         qs = [] #so here I am creating a list for all of the questions
  22.         with open("questions.txt", mode="r",encoding="utf-8") as question:
  23.             reader = csv.reader(question)
  24.             for row in reader:
  25.                 qs.append(row)
  26.         uno = qs[que] #return of the 'que' variable. this bit of code makes it so that the variable uno is set to the 'que' position in the list
  27.         print(uno) #for example, if que = 3, then it would read the 4th line of the list (lists start at 0)
  28.         ans = [] #another list creation just here
  29.         with open("answers.txt", mode="r",encoding="utf-8") as answer:
  30.             reader = csv.reader(answer)
  31.             for row in reader:
  32.                 ans.append(row)
  33.         dos = ans[anw] #same basic logic as above here
  34.         print(dos)
  35.         ans1 = input()
  36.         if ans1 == dos: #this is where everything goes wrong, it does not accept my 'ans1' input as being the same as the line from the list
  37.             print("You are right!")
  38.             score = score + 2
  39.             print("Your score is ", score)
  40.             que = que +1 #if you get the question right, then all of the variables go up 1
  41.             anw = anw +1 #meaning that the position in the list rises by 1
  42.             hnt = (hnt)+1 #and everything repeats, thanks to the while loop.
  43.             qes = True #since all the variables have changed, now there will be different questions, answers and hints shown
  44.         else:
  45.             if (ans1) == "Hint":
  46.                 score = (score)-1
  47.                 hin = []
  48.                 with open("hints.txt", mode="r",encoding="utf-8") as hints:
  49.                     reader = csv.reader(hints)
  50.                     for row in reader:
  51.                         hin.append(row)
  52.                 print(hin[hnt])
  53.                 qes = True
  54.             else:
  55.                 print("That is incorrect. Let's start from the beginning.")
  56.                 que = 0
  57.                 anw = 0
  58.                 hnt = 0
  59.                 score = (score)-1
  60.                 qes = True
  61. else:
  62.     print("Alright then. See you next time.")
  63.     exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement