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?

More than 3 years have passed since last update.

Pythonで間違い探し

Last updated at Posted at 2020-10-12
import random

def main():

    # rnd = random.randint(50, 100)
    # rnd = random.random()
    count = 0
    postions = []

    problem = ""

    A = "ぬ"
    B = "め"

    for x in range(1, 11):
        for y in range(1, 11):

            if y % 10 == 0:
                print(A)
                problem += A + "\n"
            else:
                if random.random() < 0.1:
                    print(B, end="")
                    count = count + 1
                    problem += B

                    p = [x, y]
                    postions.append(p)
                else:
                    print(A, end="")
                    problem += A

    # print(count)
    # print(postions)
    # print("=======")
    # print(problem)


    print("--------------------")
    print("答え⬇︎")
    
    print("「め」の数は{}個".format(count))
    

    for a in postions:
        print("「め」は{}行、{}列目".format(a[0], a[1]))

    with open("result.txt", "w") as f:
        f.write("間違い探しクイズ\n")
        f.write(problem)
        f.write("「め」の数は{}個\n".format(count))

        for a in postions:
            f.write("「め」は{}行、{}列目\n".format(a[0], a[1]))

if __name__ == '__main__':
    main()

スクリーンショット 2020-10-12 13.31.58.png

縦×10、 横×10の列でランダムで『め』の位置や個数が変わります。

#最後に

理解を深める為にやったので時間はかかりましたが、ちゃんと動いて良かったです。

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?