0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

選択問題の問題集を作成する

Last updated at Posted at 2022-03-31

対象

オリジナルの問題集(選択問題)を作りたい人

使い方

step1「作成」


import json

quizes = []
while True:
    question = input('問題を入力してください(nを入力すると終了します): ')
    if question == 'n':
        break
    a = input('選択肢 1: ')
    b = input('選択肢 2: ')
    c = input('選択肢 3: ')
    d = input('選択肢 4: ')
    answer = int(input('答えを1∼4で入力してください: '))
    quiz = {
        'question': question,
        'selections': [a, b, c, d],
        'answer': answer
    }
    quizes.append(quiz)

with open('quiz.json', 'w',encoding='utf-8') as f:
    json.dump(quizes, f, indent=4, ensure_ascii=False)

step2「解く」


import random
import json

with open("quiz.json",encoding='utf-8') as f:
    quizes = json.load(f)
    random.shuffle(quizes)

print("START")
correct = 0
wrong = 0
for quiz in quizes:
    print(quiz["question"])
    for i, selection in enumerate(quiz["selections"], 1):
        print(f"  {i}: {selection}")
    your_answer = input(f"番号で回答してください(fを入力すると終了) ").strip()
    if your_answer == "f":
        break
    if your_answer == str(quiz["answer"]):
        print('')
        correct += 1
    else:
        print('×')
        wrong += 1

print()
print('結果:')
print(f'◯→{correct}')
print(f'×→{wrong}')
print(f'{(correct/(correct + wrong))*100}%')


作成した問題集をコピペで共有したりするのも良さそうですね!ご活用ください!

コメント大変勉強になります!
ありがとうございます!

0
0
4

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?