|
发表于 2020-3-22 14:19:11
|
显示全部楼层
有改进的地方请提出
# -*- coding: gbk -*-
import random
result = '×××'
time = 4
count = 1
def chushi():
global secret
a = str(random.randint(0,9))
b = str(random.randint(0,9))
c = str(random.randint(0,9))
secret = a+b+c
return secret
def panduan(secret,guess):
global result
for i in range(3):
if guess[i] in secret:
if guess[i] == secret[i]:
result = result[:i] + '○' + result[i+1:]
else:
result = result[:i] + '△' + result[i+1:]
return result
chushi()
print(secret)
while 1:
if count == 1:
cao = '猜猜我想的哪个数字:'
else:
cao = '重猜一遍吧:'
count = 0
guess = input(cao)
while (not guess.isdigit()) or (len(guess) != 3):
print('请输入一个三位数')
guess = input(cao)
time -= 1
xi = panduan(secret,guess)
print(xi)
if xi == '○○○':
print('OHohhhhhhhhhhhhhhhh!!')
print('猜对了!')
break
elif xi == '×××':
print('T_T 你是认真的吗?')
else:
print('猜错了')
if time == 0:
print('机会用完了...')
break |
|