python0表示剪刀_石头,纸,剪刀Python代码。帮助简化

我是Python新手,只写过几个程序。这是我最近为一个“石头剪子”游戏编写的代码。我已经测试过了,效果很好。有什么方法可以简化它吗?谢谢!import random

wins=0

losses=0

ties=0

rounds=0

r=1 #rock

p=2 #paper

s=3 #scissors

y = "The computer has made its choice, how about you?"

while rounds <= 10:

print y

x = input('(1)rock, (2)paper, or (3)scissors? :')

choice = x

cpu_choice= random.randint(1, 3)

if (choice, cpu_choice) == (1, 2):

rounds += 1

losses += 1

print 'computer chose paper, you lose'

elif (choice, cpu_choice) == (3, 2):

print 'you win'

rounds += 1

wins += 1

elif (choice, cpu_choice) == (2, 2):

print 'TIE!'

rounds += 1

ties += 1

elif (choice, cpu_choice) == (1, 3):

print 'you win'

rounds += 1

wins += 1

elif (choice, cpu_choice) == (3, 3):

print 'TIE!'

rounds += 1

ties += 1

elif (choice, cpu_choice) == (2, 3):

print 'computer chose scissors, you lose'

rounds += 1

losses += 1

elif (choice, cpu_choice) == (1, 1):

print 'TIE'

rounds += 1

ties += 1

elif (choice, cpu_choice) == (3, 1):

print 'computer chose rock, you lose'

rounds += 1

losses += 1

elif (choice, cpu_choice) == (2, 1):

print 'you win'

rounds += 1

wins += 1

else:

print 'Please choose 1, 2, or 3'

print 'Game Over'

if wins>losses:

print 'YOU WON'

print 'wins:' , wins

print 'losses' , losses

print 'ties' , ties

else:

print 'you lose'

print 'wins:' , wins

print 'losses:' , losses

print 'ties:' , ties

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值