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?

はじめに

Pythonの更新形式の出力を勉強したので,それを用いてフラッシュ暗算を実装しようと思いました

フラッシュ暗算とは

  • コンピュータ画面などにフラッシュ表示される数字を頭の中で足し合わせて答えを出す種目

Pythonコード

  • 桁数,計算回数,表示時間を調整可能にしました
import numpy as np
import time

def clear_lines(num_lines):
  for _ in range(num_lines):
    print('\033[F\033[K', end='')

digit = int(input('桁数 >> '))
n = int(input('計算回数 >> '))
t = float(input('表示時間 >> '))
r = np.random.randint(10**(digit-1),10**digit-1,n)
exp = ''
for i in range(n):
  exp += str(r[i])
  if i < n-1:
    exp += ' + '
ans = sum(r)
for num in r:
  print(num)
  time.sleep(t)
  clear_lines(1)
if int(input('answer >> ')) == ans:
  print('True')
else:
  print('False')
  print(exp)
  print('The answer is', ans)

今後

  • print文の表示が小さいので,アスキーアートなどで数字を大きく表示できたら面白いなと思いました
0
0
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
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?