python GUI 猜数字游戏

用python写的猜数字游戏。
[cc lang=”python”]
# -*- coding:utf-8 -*-
import easygui,random
status = easygui.buttonbox(“这是一个猜数字游戏,点击开始进行游戏,点击退出关闭游戏。”, choices = [“开始”,”退出”])
if status == “开始”:
s_number = random.randint(1,100)
count = 0
u_number = 0
#print s_number
while count < 6 and u_number != s_number: u_number = int(easygui.enterbox("请输入一个1-100的数字:")) if u_number == s_number: easygui.msgbox("恭喜你猜对了") break elif u_number < s_number: easygui.msgbox("小了") #print u_number else: easygui.msgbox("大了") #print u_number count = count + 1 else: easygui.msgbox("六次了你都没有猜中") #print s_number else: easygui.msgbox("退出游戏!") #print "exit" [/cc]

Leave a Reply