Skip to content

Instantly share code, notes, and snippets.

@dev001hajipro
Created October 4, 2017 09:15
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 dev001hajipro/396b6641674391afe99945f1825dad9b to your computer and use it in GitHub Desktop.
Save dev001hajipro/396b6641674391afe99945f1825dad9b to your computer and use it in GitHub Desktop.
Pythonで数字あてゲーム
# -*- coding:utf-8 -*-
""" 数あてゲーム """
import random
class GuessTheNumber:
""" 数あてゲーム """
VERSION = 1.0
def __init__(self):
self.secretNumber = random.randint(1, 20)
def run(self):
found_flag = False
for i in range(1, 7): # loop 6 times from 1.
print('数字を入力してください。')
guess = int(input())
if guess < self.secretNumber:
print('あなたの推測した数字は小さいです。')
elif guess > self.secretNumber:
print('あなたの推測した数字は大きいです。')
else:
print('答えは ' + str(guess))
print('Good job! あなたの推測した回数は、' + str(i) + ' です。')
found_flag = True
break
if not found_flag:
print('コンピュータは、 ' + str(self.secretNumber) + 'を用意してました。')
if __name__ == '__main__':
g = GuessTheNumber()
g.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment