diff options
author | Olivier Gayot <olivier.gayot@sigexec.com> | 2020-05-06 17:23:30 +0200 |
---|---|---|
committer | Olivier Gayot <olivier.gayot@sigexec.com> | 2020-05-06 17:23:30 +0200 |
commit | 06bb76c279f1fd2f8e7806033e44f1eaa8779561 (patch) | |
tree | 1ca239566a5b2c0b07efe348541ed9da1fdfcec9 | |
parent | 708c741dcb980c65c4bbea1a36b57773c5595389 (diff) |
Add the python script which runs the exercise
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
-rw-r--r-- | very.py | 28 |
1 files changed, 28 insertions, 0 deletions
@@ -0,0 +1,28 @@ +#!/usr/bin/env python3 + +import json +import random + + +def main(): + dictionary = json.load(open("dict.json", mode="r", encoding="utf-8")) + + correct = 0 + for counter, (question, answer) in enumerate(random.sample(dictionary, len(dictionary))): + print(f"Very {question} -> ", end="") + try: + user_input = input() + except EOFError: + break + if user_input.lower() == answer.lower(): + print("Correct!") + correct += 1 + else: + print(f"Wrong! The answer was {answer}") + + + print(f"Result: {correct}/{counter}") + + +if __name__ == "__main__": + main() |