LoginSignup
1
1

More than 1 year has passed since last update.

一問一答の問題集を作成する。

Last updated at Posted at 2022-03-29

使い方
please input questionで「nothing」と入力すると問題集の作成が終わります。
回答時に「finish」と入力すると回答が終わり◯の数、×の数、正解率を表示します。

①実行

import random

print("START")
questions = {}

while True:
    question = input("please input question")
    if question == "nothing":
        break
    answer = input("please input answer")
    questions[question] = answer
    print(questions)    

    
o = 0
x = 0    
while True:	
    g = random.choice(list(questions.items()))
    your_answer = input(f'{g[0]}')
    if your_answer == g[1]:
        print('')    
        o += 1
    elif your_answer == "finish":
        break
    else:
        print('×')
        x += 1
       
print(f'◯→{o}\n×→{x}')
print(f'{(o/(o + x))*100}%')

②上のコードで終了するとせっかく作った問題集が消えてしまうため、辞書型{}の部分をコピペして下のコードに貼り付けてください。(①はプレビューとして使ってください)

import random
  
questions = {この中に入れてください}
    
o = 0
x = 0    
while True:	
    g = random.choice(list(questions.items()))
    your_answer = input(f'{g[0]}')
    if your_answer == g[1]:
        print('')    
        o += 1
    elif your_answer == "finish":
        break
    else:
        print('×')
        x += 1
       
print(f'◯→{o}\n×→{x}')
print(f'{(o/(o + x))*100}%')

1
1
0

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
1
1