0
1

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 5 years have passed since last update.

python3 簡単なタイピングテストプログラム

Last updated at Posted at 2017-01-27

python3 簡単なタイピングテストプログラム

構成

  1. ソースコード 
  2. 説明

ソースコード

import sys
import random

list1 = ["りんご","きうい","めろん","れもん","すいか","ぶどう","にんじん","たまねぎ","じゃがいも","しお"]

random.shuffle(list1)

input_text = ""
for word in list1:
    while not(word == input_text):
        if input_text == "//stop":
            sys.exit()
        print("======== {} ========".format(word))
        input_text = input()

説明

まず初めに、この説明は

  • 変数の代入
  • for文
  • while文
  • import文
  • print関数

ぐらいがわかる人を対象としているのでご了承ください。それでは説明していきます。
まず、import文でsysとrandomをインポートして来ています。
そして、list1に問題のリストを代入して、shuffle関数でシャッフルしています。
この関数はリストなどの値の並びをランダムに変えるので、ランダムに順番が変わります。
それから、input_textに空文字を代入しています。これはのちに使うために用意している形です。
ここからfor文で1つ1つの問題を処理していきます。
while文は1度目はinput_textが空文字なのでTrueとなり、input関数によってinput_textにユーザーからの値が代入されます。
2度目以降は、問題と一致するまで繰り返すようになっています。
ちなみに、 //stop と打つと、問題に関係なくプログラムが終了するようになっています。

説明は以上です。
質問や改善したほうがいい点などがあれば、是非お書きください。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?