ITPub博客

首页 > IT职业 > IT图书 > python小游戏(剪刀石头布)

python小游戏(剪刀石头布)

IT图书 作者:myiee 时间:2021-09-09 09:27:00 0 删除 编辑

#!/usr/bin/python
#-- coding: utf8--
import random    #导入随机数的模块

computer = random.choice(['石头', '剪刀', '布'])
player = raw_input('请出拳(石头/剪刀/布): ')

print "Your choice: %s, Computer's choice: %s" % (player, computer)
if player == '石头':
if computer == '石头':
print '平局'
elif computer == '剪刀':
print 'You WIN!!!'
else:
print 'You LOSE!!!'
elif player == '剪刀':
if computer == '石头':
print 'You LOSE!!!'
elif computer == '剪刀':
print '平局'
else:
print 'You WIN!!!'
else:
if computer == '石头':
print 'You WIN!!!'
elif computer == '剪刀':
print 'You LOSE!!!'
else:
print '平局'

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/3702/viewspace-2803150/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-08-30

  • 博文量
    89
  • 访问量
    863