uquiz/uquiz

59 lines
1.6 KiB
Plaintext
Raw Normal View History

2020-03-13 21:03:23 +00:00
#!/usr/bin/env python3
2020-03-13 22:50:13 +00:00
import sys, os, json, hashlib
2020-03-13 21:03:23 +00:00
motd="""
\033c
_
_ _ __ _ _ _(_)____
| | | |/ _` | | | | |_ /
| |_| | (_| | |_| | |/ /
\__,_|\__, |\__,_|_/___|
|_|
uquiz is a simple user based quiz engine
"""
print(motd)
if len(sys.argv) < 2:
print('run with the uquiz file as an arg to start')
sys.exit()
2020-03-13 22:50:13 +00:00
filename=sys.argv[1]+'.json'
answers = []
done = False
def hashme(inp):
return hashlib.md5(inp.encode("utf-8")).hexdigest()[:9]
2020-03-13 21:03:23 +00:00
with open(filename, 'r') as file:
2020-03-13 22:50:13 +00:00
data = json.load(file)
print(data["message"])
for question in data["q"]:
print('Question {}: {}'.format(data["q"].index(question)+1, question['q']))
for ans in question["o"]:
print("{}) {}".format(data["t"][question["o"].index(ans)],ans))
chosen = 0
while not chosen in data["t"]:
chosen = input('> ').lower()
answers.append(data["t"].index(chosen))
print('Test done! input the salt to see your score, if you dont have it then just press enter.')
while not done:
score = 0
nques = 0
salt = input('salt> ')
if salt:
for i in range(len(answers)):
nques+=1
print(str(hashme(salt+data["q"][i]["o"][answers[i]])))
if str(hashme(salt+data["q"][i]["o"][answers[i]])) == data["q"][i]["c"]:
score+=1
print("You got {}% ({}/{})".format((score/nques)*100, score, nques))
print("Your answers were: "+" ".join([str(a) for a in answers]))
if input("done? (yes)> ") == "yes":
done = True
2020-03-13 21:03:23 +00:00