Advertisement
serd2011

225608331.py

Jul 20th, 2021 (edited)
792
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.89 KB | None | 0 0
  1. import io
  2. import json
  3. import random
  4.  
  5. questionsFile = io.open("questions.json", 'r', encoding='utf8')
  6. questions = json.load(questionsFile)["questions"]
  7. questionsFile.close()
  8.  
  9. questionsIndexes = list(range(0, len(questions)))
  10. random.shuffle(questionsIndexes)
  11.  
  12. score = 0
  13.  
  14. for i in range(0, len(questionsIndexes)):
  15.     question = questions[questionsIndexes[i]]
  16.     print("{0}) {1}:".format(i+1, question["question"]))
  17.     userAnswer = input().lower()
  18.     if(userAnswer == question["answer"].lower()):
  19.         print("Правильно!")
  20.         score += 1
  21.     else:
  22.         print("Ошибка! Правильный ответ: ", question["answer"])
  23.  
  24. print("Твой счет: ", score)
  25.  
  26.  
  27. // Дальше файл questions.json
  28. {
  29.     "questions": [
  30.         {
  31.             "question": "Самая высокая гора в солнечной системе",
  32.             "answer": "олимп"
  33.         },
  34.         {
  35.             "question": "Какая высота у горы Олимп в км",
  36.             "answer": "26"
  37.         },
  38.         {
  39.             "question": "У какого животного имеются гены и птицы, и рептилии, и млекопитающего",
  40.             "answer": "утконос"
  41.         },
  42.         {
  43.             "question": "Самая близкая к нам галактика",
  44.             "answer": "галактика андромеда"
  45.         },
  46.         {
  47.             "question": "В какю игру любят играть все школьники",
  48.             "answer": "бравл старс"
  49.         },
  50.         {
  51.             "question": "Кто создал игру Gеomеtry Dash",
  52.             "answer": "Robtop"
  53.         },
  54.         {
  55.             "question": "Самая близкая к нам солнечная система",
  56.             "answer": "альфа центвара"
  57.         }
  58.     ]
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement