0

posted at

updated at

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

## 対象

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

## 使い方

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: ')
quiz = {
'question': question,
'selections': [a, b, c, d],
}
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:
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}")
break
print('◯')
correct += 1
else:
print('×')
wrong += 1

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

``````

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

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
What you can do with signing up
0