Created
December 19, 2020 04:40
-
-
Save coding-youtuber/93bbbd22a0fac7aeb3865ff0ccbe5d4e to your computer and use it in GitHub Desktop.
20行で書けるPythonのゲーム「数当てゲーム」
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
print("数当てゲームを始めます") | |
print("答えの数の範囲は1~100です") | |
answer = random.randrange(start=1, stop=100) | |
guess = int(input("あなたが予想する数字:")) | |
tries = 1 | |
while(guess != answer): | |
# 予想が外れている限り、whileの中身を実行する | |
if(guess > answer): | |
print("あなたの予想した数は答えより大きいです") | |
else: | |
print("あなたの予想した数は答えより小さいです") | |
tries = tries + 1 | |
guess = int(input("あなたが予想する数字:")) | |
# whileが終了したので予想が当たった | |
print("正解です。答えは{}".format(answer)) | |
print("あなたの試行回数は{}でした".format(tries)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment