0
2

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 1 year has passed since last update.

pythonで作る数当てゲーム

Last updated at Posted at 2021-11-23

1~100のランダムな数字を当てるゲームです。

kazuate.py
import random
count = 1
answer = random.randint(1,100)

while True:
    number = input('1~100の間で数字を入力してください >> ')
    if number.isdecimal():
        number = int(number)
    else:
        print('間違った入力がされました。\n'
              'もう一度数字の入力をお願いします。')
        continue

    if answer == number:
        print(f'正解です。正解は{answer}')
        print(f'{count}回目のチャレンジで正解しました。')
        break
    elif answer > number:
        print(f'入力された数字は{number}。それより大きい数です。')
        count += 1
    else:
        print(f'入力された数字は{number}。それより小さい数です。')
        count += 1

動作のスクリーンショットなど
スクリーンショット 2021-11-23 171757.png

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?