|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import easygui as g
import sys
import random
def bet(computer_choice,choice):
if computer_choice != choice:
if computer_choice=='石头' and choice=='剪刀':
result='电脑赢了'
elif computer_choice=='剪刀' and choice=='布':
result='电脑赢了'
elif computer_choice=='布' and choice=='石头':
result='电脑赢了'
else:
result='你赢了'
else:
result='平局'
return result
while True:
num=random.randint(1,3)
if num==1:
computer_choice='石头'
elif num==2:
computer_choice='剪刀'
elif num==3:
computer_choice='布'
g.msgbox('开始猜拳游戏')
msg='请问你希望出什么呢?'
title='小游戏互动'
choices=['石头','剪刀','布']
choice=g.choicebox(msg,title,choices)
g.msgbox('你的选择是:'+str(choice)+'\n'+'电脑的选择是:'+str(computer_choice) +'\n'+ '\t'+ bet(computer_choice,choice)+'!!!','结果')
msg='你希望重新开始猜拳游戏吗?'
title='请选择'
if g.ccbox(msg,title):
pass
else:
sys.exit(0)
- import easygui as g
- import random
- def bet(computer_choice,choice):
- if computer_choice-choice == -1 or computer_choice-choice == 2:
- result='电脑赢了'
- elif computer_choice-choice == 0:
- result='平局'
- else:
- result='你赢了'
- return result
-
- RPS=['石头','剪刀','布']
- while True:
- num=random.randint(1,3)
- g.msgbox('开始猜拳游戏')
- msg='请问你希望出什么呢?'
- title='小游戏互动'
- uchoice=g.indexbox(msg,title,choices=RPS)
- g.msgbox('你的选择是:%s\n电脑的选择是:%s\n\t%s!!!'% (RPS[uchoice], RPS[num-1],bet(num-1,uchoice)),'结果')
- msg='你希望重新开始猜拳游戏吗?'
- title='请选择'
- if not g.ccbox(msg,title):
- break
复制代码
|
|