-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtesting.py
More file actions
107 lines (93 loc) · 3.64 KB
/
Copy pathtesting.py
File metadata and controls
107 lines (93 loc) · 3.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
'''
I made this in like 2013 and I uploaded it to another account on here that I lost access to.
I can not remember if all of this code is originally mine or not. -> herenti
'''
import random
import time
'''
takes a list of tuple pairs for questions
example [('what is my name?','azuriah'),('what is my favorite color?','blue')]
call
if __name__ == '__main__':
test.Test(questions, #howmanychoices)
from another file
'''
letters = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
class gTest:
def __init__(self, questions, choices):
self.questions_dict = dict(questions)
self.x = random.choice(questions)[0]
self.choices = int(choices)
self.answers = list()
self.question = dict()
self.answer = self.questions_dict[self.x]
self.answer_letter = None
self.get_answers()
def get_answers(self):
new_set = list(self.questions_dict.items())
while len(self.answers) < self.choices:
random.shuffle(new_set)
y = random.choice([b for a, b in dict(new_set).items() if a != self.x])
self.answers.append(y)
self.answers = list(set(self.answers))
self.make_list()
def make_list(self):
self.answers.append(self.answer)
values = self.answers
random.shuffle(values)
values = [{letters[i]: values[i]} for i in range(len(values))]
for x in values:
for i in x.keys():
if x[i] == self.answer:
self.answer_letter = i
break
self.question[self.x] = values
class Test:
def __init__(self, questions, choices, language = False, reading = False):
self.initialize = questions
self.choices = choices
self.language = language
self.reading = reading
self.key = gTest(self.initialize, self.choices)
self.question = self.key.question
self.answer = self.key.answer_letter
self.x = self.key.x
self.check = None
self.start()
def check_answer(self):
if self.check == self.answer:
print('correct')
key = gTest(self.initialize, self.choices)
self.question = key.question
self.answer = key.answer_letter
self.x = key.x
time.sleep(1)
self.start()
else:
print('incorrect')
time.sleep(1)
self.start()
def start(self):
answers = []
reading = []
question = []
if self.language:
for i in self.question[self.x]:
if self.reading:
if list(i)[0] == self.answer:
if len(i[list(i)[0]].split()) > 1:
question.append('%s: %s' % (self.x, i[list(i)[0]].split(' ',1)[0]))
else: question.append('%s' % self.x)
try: answers.append('%s: %s' % (list(i)[0], i[list(i)[0]].split(' ',1)[1]))
except IndexError: answers.append('%s: %s' % (list(i)[0], i[list(i)[0]].split(' ',1)[0]))
if not self.reading: question.update(self.x)
else:
for i in self.question[self.x]:
answers.append('%s: %s' % (list(i)[0], i[list(i)[0]]))
question.append(self.x)
print('question: '+' '.join(question))
for x in answers:
print(x)
answer = input('answer: ')
self.check = answer
self.check_answer()