functional

This commit is contained in:
lickthecheese 2020-03-13 18:50:13 -04:00
parent cd8e9c5a45
commit b78eef2c77
1 changed files with 35 additions and 4 deletions

39
uquiz
View File

@ -1,6 +1,6 @@
#!/usr/bin/env python3
import sys, os, json
import sys, os, json, hashlib
motd="""
\033c
@ -19,9 +19,40 @@ if len(sys.argv) < 2:
print('run with the uquiz file as an arg to start')
sys.exit()
filename=sys.argv[1]
filename=sys.argv[1]+'.json'
answers = []
done = False
def hashme(inp):
return hashlib.md5(inp.encode("utf-8")).hexdigest()[:9]
with open(filename, 'r') as file:
data = jason.load(file)
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