用户:虚假的馒头查看:0 回复:0 评论:0 创建时间:2022-06-01T10:33:22
【作品展示】

【作品介绍】
yee
【作品源代码】
import random
import string
letter = string.ascii_lowercase
#随机生成字符串
n = random.randint(5, 20)
strings = ""
for i in range(n):
char = random.choice(letter)
strings = strings + char
str_list=list(strings)
print(strings)
print("回文游戏")
round = 1
while True:
print("==============================================================")
print("第{}回合".format(round))
#抽取字符
print("现在的字符窜是:{}".format(str_list))
your = input(">>请选择你要拿走的字符:")
if your in str_list:
id = str_list.index(your)
str_list.pop(id)
print("你选择拿走的字符窜是:{}".format(your))
print("你抽取后:{}".format(str_list))
else:
print("你选择的字符不存在再选择一个")
continue
#判断
odd_count = 0
char_count = []
for char in str_list:
for char in str_list:
if char not in char_count:
char_count.append(char)
num = str_list.count(char)
if num % 2 == 1:
odd_count = odd_count + 1
if odd_count <= 1:
print(">>你赢了!")
break
round = round + 1
#抽取字符
print("现在的字符窜是:{}".format(str_list))
your = random.choice(str_list)
id = str_list.index(your)
str_list.pop(id)
print("电脑选择拿走的字符窜是:{}".format(your))
print("电脑抽取后:{}".format(str_list))
#判断
odd_count = 0
char_count = []
for char in str_list:
for char in str_list:
if char not in char_count:
char_count.append(char)
num = str_list.count(char)
if num % 2 == 1:
odd_count = odd_count + 1
if odd_count <= 1:
print(">>电脑赢了!")
break
round = round + 1
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn