From b78eef2c778d5b47f3fdb9144bbf6840c05de81e Mon Sep 17 00:00:00 2001 From: lickthecheese Date: Fri, 13 Mar 2020 18:50:13 -0400 Subject: [PATCH] functional --- uquiz | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/uquiz b/uquiz index 3e1e701..60d9d6e 100755 --- a/uquiz +++ b/uquiz @@ -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 +