Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import io
- import json
- import random
- questionsFile = io.open("questions.json", 'r', encoding='utf8')
- questions = json.load(questionsFile)["questions"]
- questionsFile.close()
- questionsIndexes = list(range(0, len(questions)))
- random.shuffle(questionsIndexes)
- score = 0
- for i in range(0, len(questionsIndexes)):
- question = questions[questionsIndexes[i]]
- print("{0}) {1}:".format(i+1, question["question"]))
- userAnswer = input().lower()
- if(userAnswer == question["answer"].lower()):
- print("Правильно!")
- score += 1
- else:
- print("Ошибка! Правильный ответ: ", question["answer"])
- print("Твой счет: ", score)
- // Дальше файл questions.json
- {
- "questions": [
- {
- "question": "Самая высокая гора в солнечной системе",
- "answer": "олимп"
- },
- {
- "question": "Какая высота у горы Олимп в км",
- "answer": "26"
- },
- {
- "question": "У какого животного имеются гены и птицы, и рептилии, и млекопитающего",
- "answer": "утконос"
- },
- {
- "question": "Самая близкая к нам галактика",
- "answer": "галактика андромеда"
- },
- {
- "question": "В какю игру любят играть все школьники",
- "answer": "бравл старс"
- },
- {
- "question": "Кто создал игру Gеomеtry Dash",
- "answer": "Robtop"
- },
- {
- "question": "Самая близкая к нам солнечная система",
- "answer": "альфа центвара"
- }
- ]
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement