Python实现剪刀石头布小游戏(与电脑对战)
具体代码如下所述:
srpgame.py
#!/urs/bin/envpython
importrandom
all_choice=['石头','剪刀','布']
win_list=[['石头','剪刀'],['剪刀','布'],['布','石头']]
prompt="""
(0)石头
(1)剪刀
(2)布
Pleaseinputyourchoice(0/1/2):"""
computer=random.choice(all_choice)
ind=int(input(prompt))
player=all_choice[ind]
print("Yourchoice:%s,Computer'schoice:%s"%(player,computer))
ifplayer==computer:
print('\033[32;1m平局\033[0m')
elif[player,computer]inwin_list:
print('\033[31;1mYouWIN!!!\033[0m')
else:
print('\033[31;1mYouLOSE!!!\033[0m')
演示
D:\Pythonscripts
λpython3.\srpgame.py
(0)石头
(1)剪刀
(2)布
Pleaseinputyourchoice(0/1/2):0
Yourchoice:石头,Computer'schoice:剪刀
YouWIN!!!
D:\Pythonscripts
λpython3.\srpgame.py
(0)石头
(1)剪刀
(2)布
Pleaseinputyourchoice(0/1/2):1
Yourchoice:剪刀,Computer'schoice:剪刀
平局
D:\Pythonscripts
λpython3.\srpgame.py
(0)石头
(1)剪刀
(2)布
Pleaseinputyourchoice(0/1/2):2
Yourchoice:布,Computer'schoice:石头
YouWIN!!!
D:\Pythonscripts
λpython3.\srpgame.py
(0)石头
(1)剪刀
(2)布
Pleaseinputyourchoice(0/1/2):0
Yourchoice:石头,Computer'schoice:布
YouLOSE!!!
总结
以上所述是小编给大家介绍的Python实现剪刀石头布小游戏(与电脑对战),希望对大家有所帮助!
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。
热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下