LoginSignup
0
0

More than 1 year has passed since last update.

書き方がよくわかんないからとりあえずテスト投稿

Last updated at Posted at 2022-09-08
from random import randint
import time

OPENNING_MESSAGE='''
===============
時間制限付きの計算問題です。
===============
'''

#ゲームの中身
def game():

    print(OPENNING_MESSAGE)

    question = 0 # 問題数
    miss=0 # 間違えた数
    correct=0 # 正解数

    # 問題生成
    while question<10:
        a=randint(1,100)
        b=randint(1,100)
        ans=a+b
        q=f"{a}+{b}は?:"

        # 問題文表示
        value=input(q)

        # 回答入力
        if value=="q":
            break
        if value==str(ans):
            correct+=1
            question+=1
            print("正解です!次!")
        else:
            miss+=1
            question+=1
            print("違います!次!")

    # 10問終了
    print("-"*20)
    print("ゲーム終了!結果発表!")
    print(f"正解数:{correct}、間違い数:{miss}")

    score=correct*10
    print(f"点数は・・・{score}点!" )

    # 入力直後
def play():
    op=input("ゲームを開始します。よろしいですか?(y/n):")
    if op=="y":
        print("ゲームを開始します。")
        game()
    elif op=="n":
        print("ゲームを終了します。")
    else:
        print("無効なコマンドです。")

play()
0
0
2

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