python 第2天

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 第2天相关的知识,希望对你有一定的参考价值。

import easygui,random

secret = random.randint(1,99)

easygui.msgbox("""I have a secret ,It is a number from 1-99 ,you have 6 tries

.OK let‘do it.""")

tries=0

guess=0

while tries < 6 and guess != secret:

    guess = easygui.integerbox("what‘s your guess,metey?")  

//只允许输整数,若是小数可以用 guess = float(easygui.enterbox("what‘s your guess,metey?"))

    if not guess: break

    if guess < secret:

        easygui.msgbox(str(guess)+"is too low !")

    elif guess > secret:

        easygui.msgbox(str(guess)+"is too high,landlubber!")

    tries = tries + 1

if guess == secret:

    easygui.msgbox("you got it,congratulate")

else:

    easygui.msgbox("No more chance.my secret is "+str(secret),"Test")


注意,easygui.msgbox 对应到目录中是/lib/easygui/__init__.py 中的


这是__init__.py中的内容

__all__ = [‘buttonbox‘,

           ‘diropenbox‘,

           ‘fileopenbox‘,

           ‘filesavebox‘,

           ‘textbox‘,

           ‘ynbox‘,

           ‘ccbox‘,

           ‘boolbox‘,

           ‘indexbox‘,

           ‘msgbox‘,

           ‘integerbox‘,

           ‘multenterbox‘,

           ‘enterbox‘,

           ‘exceptionbox‘,

           ‘choicebox‘,

           ‘codebox‘,

           ‘passwordbox‘,

           ‘multpasswordbox‘,

           ‘multchoicebox‘,

           ‘EgStore‘,

           ‘eg_version‘,

           ‘egversion‘,

           ‘abouteasygui‘,

           ‘egdemo‘,

]


# Import all functions that form the API

from .boxes.button_box import buttonbox

from .boxes.diropen_box import diropenbox

from .boxes.fileopen_box import fileopenbox

from .boxes.filesave_box import filesavebox


from .boxes.text_box import textbox


from .boxes.derived_boxes import ynbox

from .boxes.derived_boxes import ccbox

from .boxes.derived_boxes import boolbox

from .boxes.derived_boxes import indexbox

from .boxes.derived_boxes import msgbox   

//这里真实的目录就是 安装路径/Lib/boxes/derived_boxes

from .boxes.derived_boxes import integerbox

from .boxes.multi_fillable_box import multenterbox

from .boxes.derived_boxes import enterbox

from .boxes.derived_boxes import exceptionbox

from .boxes.choice_box import choicebox

from .boxes.derived_boxes import codebox

from .boxes.derived_boxes import passwordbox

from .boxes.multi_fillable_box import multpasswordbox

from .boxes.choice_box import multchoicebox

from .boxes.egstore import EgStore, read_or_create_settings

from .boxes.about import eg_version, egversion, abouteasygui

from .boxes.demo import easygui_demo as egdemo



msgbox(msg="(Your message goes here)", title=" ",

           ok_button="OK", image=None, root=None): 使用格式。

easygui.msgbox("""I have a secret ,It is a number from 1-99 ,you have 6 tries

.OK let‘do it.""","Test","YES","D:/picture/2.gif") //是使用事例

使用效果如图技术分享


import easygui

name = easygui.enterbox("what‘s your name?")

room_num = easygui.enterbox("what‘s your room number?")

street_num = easygui.enterbox("what‘s your street name?")

city = easygui.enterbox("what‘s your city?")

province = easygui.enterbox("what‘s your province?")

country = easygui.enterbox("what‘s your country?")

easygui.msgbox("name="+name+"\r\n"+"room_num="+room_num+"\r\n"+"street_num"+street_num+"\r\n"+"city"+city+

               "\r\n"+"province"+province+"\r\n"+"country"+country)

"\r\n" 换行显示的关键,若是linux系统中是"\n". 

本文出自 “姑苏城” 博客,请务必保留此出处http://ji123.blog.51cto.com/11333309/1964087

以上是关于python 第2天的主要内容,如果未能解决你的问题,请参考以下文章

Python第2天8题

第2天:Python 基础语法

python第3天:数据类型

Python第8天

python基础第2天-算术运算符

30天Python入门到进阶——第2天:数据类型(Ⅰ)