python小游戏完整代码

本程序需插入easygui包,以下为原代码:

import easygui as g
import random
w=1
while w:
  dn=random.randint(0,2)
  if dn==0:
      dn='石头'
  if dn==1:
      dn='剪子'
  if dn==2:
      dn='布' 
  xz=g.buttonbox("请选择你出什么?","",("石头","剪子","布","退出"))
  if xz=="退出":
      w=0
      g.msgbox("再见,欢迎下次再玩!")
  elif xz==dn:
       g.textbox("结果:","","你:"+xz+"       电脑:"+dn+"....平局!")
  elif dn=="石头" and xz=="布":
       g.textbox("结果:","","你:"+xz+"       电脑:"+dn+"....你你赢了!")
  elif dn=="布" and xz=="石头":
       g.textbox("结果:","","你:"+xz+"       电脑:"+dn+"....你你输了!")
  elif dn=="剪子" and xz=="石头":
        g.textbox("结果:","","你:"+xz+"       电脑:"+dn+"....你你赢了!")
  elif dn=="剪子" and xz=="布":
       g.textbox("结果:","","你:"+xz+"       电脑:"+dn+"....你你输了!")    
  elif dn=="布" and xz=="剪子":
      g.textbox("结果:","","你:"+xz+"       电脑:"+dn+"....你你输了!") 

你可能感兴趣的:(python,开发语言)