Created
October 4, 2017 09:15
-
-
Save dev001hajipro/396b6641674391afe99945f1825dad9b to your computer and use it in GitHub Desktop.
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
# -*- 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