Skip to content

Instantly share code, notes, and snippets.

@coding-youtuber
Created December 19, 2020 04:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coding-youtuber/93bbbd22a0fac7aeb3865ff0ccbe5d4e to your computer and use it in GitHub Desktop.
Save coding-youtuber/93bbbd22a0fac7aeb3865ff0ccbe5d4e to your computer and use it in GitHub Desktop.
20行で書けるPythonのゲーム「数当てゲーム」
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