|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
昨天刘谦表演的魔术很精彩,然后我就想着写一段代码模拟一下
结果被不二如是抢先了
我也不好意思说什么了,实力还差得远,就发自己写的分享一下
- import random
- #模拟从一副牌中挑四张牌
- cards = list(range(54))
- choices = random.sample(cards,4) #挑出来的4张牌
- #将选中的牌由序号转换为名称
- cardnames = []
- hs = {0:'梅花',1:'方块',2:'黑桃',3:'红桃'}
- ds = {0:'A',1:'2',2:'3',3:'4',4:'5',5:'6',6:'7',\
- 7:'8',8:'9',9:'10',10:'J',11:'Q',12:'K'}
- for i in choices:
- if i < 52:
- cardnames.append(hs[i//13]+ds[i%13])
- elif i == 52:
- cardnames.append('小王')
- else:
- cardnames.append('大王')
- choices = cardnames
- print('[发牌结束]\t你现在的手牌是',*choices)
- choices.extend([i + '<2>' for i in choices]) #模拟撕碎扑克牌
- name = input('请输入你的名字')
- for i in name:
- choices.append(choices.pop(0)) #将扑克牌从顶部移至底部
- print('[按名字移动牌]\t你现在的手牌是',*choices) #定期跟踪扑克牌的情况
- input('回车继续')
- def removecard(choices,x):
- removecards = choices[:x] #拿起前x张
- choices[:x] = []
- place = random.randint(1,len(choices)-1)
- choices[place:place] += removecards #插进空隙中
- removecard(choices,3)
- print('[移动前三张]\t你现在的手牌是',*choices)
- specific = choices.pop(0) #取走第一张,藏起来
- input('[取走第一张]\t回车继续')
- location = input('请输入你的地域[南方/北方/其他]')
- #南北方移牌
- if location == '南方':
- removecard(choices,1)
- elif location == '北方':
- removecard(choices,2)
- else:
- removecard(choices,3)
- print('[按南北方移牌]\t你现在的手牌是',*choices)
- xingbie = input('请输入你的性别[男/女]')
- #性别扔牌
- if xingbie == '男':
- choices.pop(0)
- else:
- choices.pop(0)
- choices.pop(0)
- print('[按性别扔牌]\t你现在的手牌是',*choices)
- input('回车继续')
- for i in '见证奇迹的时刻':
- choices.append(choices.pop(0)) #将扑克牌从顶部移至底部
- print('[见证奇迹的时刻]\t你现在的手牌是',*choices)
- input('回车继续')
- flag = False
- while len(choices) > 1:
- if flag:
- choices.pop(0)
- else:
- choices.append(choices.pop(0))
- flag = not flag
- print('[好运留下,烦恼扔走]\t你现在的手牌是',*choices)
- input('回车继续')
- if '尼格买提' in name:
- print('Oh no!尼格买提的牌没有对起来') #彩蛋
- else:
- print('你藏的牌',specific)
- print('你现在的手牌是',*choices)
- print('恭喜祈福成功!!!')
复制代码
如果发现了什么问题,欢迎批评指正
最后祝大家新年快乐,龙年大吉 |
|