【Python】基础-发牌程序
本文最后更新于 1742 天前,其中的信息可能已经有所发展或是发生改变。

[success]
扑克牌发牌程序,4个牌手,计算机将52张牌发给4名牌手。打印出控制台。
[/success]
[sourcecode language=”python” title=”demo3.py”]
import random
n=52
# 交换牌的顺序
def ge_pocker(n):
x = 100
while(x>0):
x = x-1
p1 = random.randint(0,n-1)
p2 = random.randint(0,n-1)
t = pocker[p1]
pocker[p1] = pocker[p2]
pocker[p2] = t
return pocker
# 获取牌的花色
def getColor(x):
color = ["草花","方块","红桃","黑桃"]
c = int(x/13)
if c<0 or c>=4:
return "ERROR!"
return color[c]
#获取牌的字母和数字
def getValue(x):
value = x % 13
if value==0:
return ‘A’
elif value >=1 and value<=9:
return str(value+1)
elif value == 10:
return ‘J’
elif value == 11:
return ‘Q’
elif value ==12:
return ‘K’
#把花色和字母数字拼接起来
def getPuk(x):
return getColor(x) + getValue(x)
#主程序
(a,b,c,d) = ([],[],[],[])
pocker = [i for i in range(n)]
pocker = ge_pocker(n)
print(pocker)
for x in range(13):
m = x * 4
a.append(getPuk(pocker[m]))
b.append(getPuk(pocker[m+1]))
c.append(getPuk(pocker[m+2]))
d.append(getPuk(pocker[m+3]))
a.sort()
b.sort()
c.sort()
d.sort()
print("牌手1",end=":")
for x in a:
print(x,end=" ")
print("\n牌手2",end=":")
for x in b:
print(x,end=" ")
print("\n牌手3",end=":")
for x in c:
print(x,end=" ")
print("\n牌手4",end=":")
for x in d:
print(x,end=" ")

[/sourcecode]

运行效果:

暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇