Last active
March 20, 2016 07:54
-
-
Save sizumita/cca5665a91e7014d0176 to your computer and use it in GitHub Desktop.
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 | |
#python2.7 | |
import random | |
import sys,select | |
situmonsuu = 0 | |
saigo = 0 | |
def game(situmonsuu,setei,enzan): | |
maru = 0 | |
while situmonsuu != 0: | |
if setei != 4: | |
x = random.randint(1,10) | |
y = random.randint(1,10) | |
elif setei == 4: | |
y = random.randint(1,10) | |
z = random.randint(1,10) | |
x = y * z | |
elif setei == 2: | |
x = random.randint(1,20) | |
y = random.randint(1,x) | |
if setei == 1: | |
a = x + y | |
elif setei == 3: | |
a = x * y | |
elif setei == 2: | |
a = x - y | |
elif setei == 4: | |
a = x / y | |
print(str(x) + enzan + str(y) + '=') | |
num = readline_timeout(sys.stdin, 5.0) | |
keka = saitenn(num,a) | |
kotae(keka,a) | |
if keka == True: | |
maru = maru + 1 | |
situmonsuu = situmonsuu - 1 | |
if maru == 5: | |
print '全問正解!' | |
else: | |
print('正解数' + str(maru)) | |
def kotae(keka,a): | |
if keka == True: | |
print('正解!') | |
else: | |
print('不正解' + 'A,' + str(a)) | |
def readline_timeout(fd, timeout = 1.0): | |
(r, w, e) = select.select([fd], [], [], timeout) | |
if len(r) == 0: return 'timeout' | |
elif len(r) == 1: return r[0].readline() | |
else : assert False | |
def saitenn(num,a): | |
if num == 'timeout': | |
return False | |
elif int(num) == a: | |
return True | |
else: | |
return False | |
while situmonsuu == 0: | |
print('足し算ゲーム!全部で5問。1問5秒。') | |
strt = input('足し算をしたい時は1,引き算をしたい時は2,掛け算をしたい時は3,割り算をしたい時は4を押してください。始まります。') | |
if strt == 1: | |
situmonsuu = 5 | |
setei = 1 | |
enzan = '+' | |
elif strt == 3: | |
situmonsuu = 5 | |
setei = 3 | |
enzan = '*' | |
elif strt == 2: | |
situmonsuu = 5 | |
setei = 2 | |
enzan = '-' | |
elif strt == 4: | |
situmonsuu = 5 | |
setei = 4 | |
enzan = '/' | |
while saigo == 0: | |
game(situmonsuu,setei,enzan) | |
reject = input('もう一度やりますか?やる時は1、終わりたい時は他のキーを押してください。') | |
if reject != 1: | |
saigo = 1 | |
elif reject == 1: | |
strt = input('足し算をしたい時は1,引き算をしたい時は2,掛け算をしたい時は3,割り算をしたい時は4を押してください。始まります。') | |
if strt == 1: | |
situmonsuu = 5 | |
setei = 1 | |
elif strt == 3: | |
situmonsuu = 5 | |
setei = 3 | |
elif strt == 4: | |
situmonsuu = 5 | |
setei = 4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment