Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.