#guessNum
import random
tNum = []
tFlag = [0,0,0,0,0,0,0,0,0,0]
print "GuessNumber GAME START!"
tNum.append(random.randint(0,9))
tFlag[tNum[0]]= 1
for i in range(1,4):
t = random.randint(0,9)
while(tFlag[t] == 1):
t = random.randint(0,9)
tNum.append(t)
tFlag[t]= 1
while True:
#str input catch
strIn = raw_input('Please input your number/n')
bolInput = True
while True:
if len(strIn) == 4:
tbol = True
for i in range(0,4):
if not(strIn[i] >='0' and strIn[i]<='9'):
tbol = False
bolInput = False
else:
bolInput = False
if bolInput:
break
else:
strIn = raw_input('Your Input Bad!/nPlease input your number/n')
bolInput = True
#result
A = 0
B = 0
#str check
useIn =[]
for i in range(0,4):
useIn.append(int(strIn[i]))
for i in range(0,4):
if useIn[i] == tNum[i]:
A = A+1
elif tFlag[useIn[i]] == 1:
B = B+1
if A == 4:
print 'you win'
raw_input()
break
else:
print '%dA%dB/n'%(A,B)
文曲星中的猜数字游戏 python 实现
最新推荐文章于 2024-05-21 11:41:17 发布