Commit ed4145d1 by BellCodeEditor

auto save

parent 92449b0c
Showing with 99 additions and 5 deletions
list1 = []
for a in range(0, 1000):
for b in range(0, 1000):
list1.insert(0, 0)
\ No newline at end of file
import random,time
print("~"*145)
print(''' 猜数字游戏
规则:答案是五个0-9之间没有重复的数字组合而成,您猜五个数(输入五个数),
电脑根据答案每次做出判断,判断结果为ABX,结果排序是不对应目标数字组合的。
1."A" 数字对位置对
2."B" 数字对位置不对
3."X" 数字位置都不对
五次以内猜对奖励红包666,徐老师那里领取,截图为证!⭐ ⭐ ⭐
''')
print("~"*145)
# 裁判数字
goal_list = []
num = 1
while len(goal_list)<5:
#a = input("请输入目标数组的第"+str(num)+"个数:")
a = random.randint(0,9)
a = str(a)
if len(a) != 1:
print('请录入不重复的数字')
continue
else:
try:
a = int(a)
except:
print('请输入整数')
continue
if a in goal_list:
print("请输入一个不重复的整数数!")
continue
else:
goal_list.append(a)
num += 1
# 游戏开始
print("数组已生成,游戏开始!")
print(" 目标数字组合: * * * * * ")
#print(goal_list)
print("准备好了吗,要开始了哦!")
time.sleep(3)
print()
print("开始→ ")
answer_list = ["A","A","A","A","A",]
n = 1
print("-"*20+"第"+str(n)+"次!"+"-"*20)
an_list = [] # 输出答案
# 玩家输入
p_list = [] # 玩家列表
while True:
while True:
b = input("输入数字:") # 还缺少限制输入数字的重复性
if len(b) == 5:
b=list(b)
for i in range(5):
p_list.append(int(b[i]))
break
else:
print()
print("请输入5个自然数→")
print("*"*16)
# 判断
for i in range(5):
if p_list[i] in goal_list: # 判断当前数和位置是否正确
if p_list[i] == goal_list[i]:
an_list.append("A")
else:
an_list.append("B")
else:
an_list.append("X")
an_list.sort()
if an_list == answer_list:
print("恭喜你猜"+str(n)+"次就猜对了,真是太厉害了!")
break
else:
print()
print("猜数结果:",an_list)
print()
print("再来")
an_list.clear()
p_list.clear()
n += 1
print("-"*15+"第"+str(n)+"次!"+"-"*15)
\ No newline at end of file
= 158
print()
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment