dsqzhaoyue 发表于 2018-8-12 09:20:55

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)",>  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".
  for looper in range(1,5):
  print (looper)
  注意这里只会打印出1,2,3,4
  for looper in range(1,10,2): //这里的步长为2.从1,10.当然步长也可以为负数/
  print (looper)
  //小的倒计时器
  import time
  for i in range(10,0,-1):
  print (i)
  time.sleep(1)
  print ("BLASH OFF!")
  for i in ["jixaing"]: #注意与下面的区别 按字符串算一个
  print (i+"is coolest guy!")
  for i in "jixaing": #按字符输出多个
  print (i+"is coolest guy!")
页: [1]
查看完整版本: python 第2天