-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLabSafetyQuizz.py
executable file
·66 lines (62 loc) · 2.09 KB
/
LabSafetyQuizz.py
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
#!/usr/bin/python
# Written in Python 3.5 in 2019 by gaenssle
# Asks a series of questions on the correct lab handling
# Teaches lab safety
import random
# Import file containing the questions and answeres
def ImportQuizz():
Quizz = []
Index = "a"
for DecodedLineOfFile in open("LabSafetyQuizz_Linux.txt", 'r', encoding="utf8"):
DecodedLineOfFile = DecodedLineOfFile.rstrip()
LineOfFile = DecodedLineOfFile.split('_')
if len(LineOfFile) == 3:
if LineOfFile[0].isnumeric():
Question = LineOfFile[2]
Reply ={}
Step = {}
if LineOfFile[1] == "A":
Answer = LineOfFile[2]
Index = LineOfFile[0]
if LineOfFile[0] == Index and LineOfFile[1] == "R":
Reaction = LineOfFile[2]
Reply.update({Answer:Reaction})
else:
Step.update({Question:Reply})
Quizz.append(Step)
Step.update({Question:Reply})
Quizz.append(Step)
return(Quizz)
# Conduct the quizz
def ConductQuizz(Quizz):
Repeat = False
for Steps in range(len(Quizz)):
for Question, Reply in Quizz[Steps].items():
print("\nQuestion %s:\n%s" % (Steps+1, Question))
Index = 1
Consequence =[]
for Answer, Reaction in sorted(Reply.items(), key=lambda x: random.random()):
print("%s\t%s" %(Index, Answer))
Consequence.append(Reaction)
Index += 1
ChosenAnswer = input("You do:\t")
while ChosenAnswer.isnumeric()==False or int(ChosenAnswer) not in range(1,Index):
ChosenAnswer = input("\nPlease enter a number between 1 and %s\n" %(Index-1))
print("\n%s" %(Consequence[int(ChosenAnswer)-1]))
if Consequence[int(ChosenAnswer)-1].startswith("You fool!"):
Proceed = input("\nYou have failed to leave everything in one piece! "
"What do you do now?\na\tquit\nb\tstart again\n")
while Proceed not in ("a", "b"):
Proceed = input("Please enter 'a' or 'b'!")
if Proceed == "a":
quit()
else:
Repeat = True
break
print("\nCongratulations! You have managed to leave the lab!")
return(Repeat)
# Start of Script
Quizz = ImportQuizz()
Repeat = ConductQuizz(Quizz)
while Repeat == True:
Repeat = ConductQuizz(Quizz)