摘要: Python 语言允许在一个循环体里面嵌入另一个循环。 Python for 循环嵌套语法: Python while 循环嵌套语法: 你可以在循环体内嵌入其他的循环体,如在while循环中可以嵌入for循环, 反之,你可以在for循环中嵌入while循环。 以下实例使用了嵌套循环输出2~100之间 阅读全文
posted @ 2016-05-27 23:14 七月的尾巴_葵花 阅读(204) 评论(0) 推荐(0) 编辑
摘要: Python break语句,就像在C语言中,打破了最小封闭for或while循环。 break语句用来终止循环语句,即循环条件没有False条件或者序列还没被完全递归完,也会停止执行循环语句。 break语句用在while和for循环中。 如果您使用嵌套循环,break语句将停止执行最深层的循环, 阅读全文
posted @ 2016-05-27 23:14 七月的尾巴_葵花 阅读(171) 评论(0) 推荐(0) 编辑
摘要: Python程序语言指定任何非0和非空(null)值为true,0 或者 null为false。 Python 编程中 if 语句用于控制程序的执行,基本形式为: if 判断条件: 执行语句…… else: 执行语句…… 其中"判断条件"成立时(非零),则执行后面的语句,而执行内容可以多行,以缩进来 阅读全文
posted @ 2016-05-27 23:13 七月的尾巴_葵花 阅读(286) 评论(0) 推荐(0) 编辑
摘要: python 编程中 while 语句用于循环执行程序,即在某条件下,循环执行某段程序,以处理需要重复处理的相同任务。其基本形式为: 执行语句可以是单个语句或语句块。判断条件可以是任何表达式,任何非零、或非空(null)的值均为true。 当判断条件假false时,循环结束。 while 语句时还有 阅读全文
posted @ 2016-05-27 23:13 七月的尾巴_葵花 阅读(159) 评论(0) 推荐(0) 编辑
摘要: Python for循环可以遍历任何序列的项目,如一个列表或者一个字符串。 语法: for循环的语法格式如下: 通过序列索引迭代 另外一种执行循环的遍历方式是通过索引,如下实例: 以上实例我们使用了内置函数 len() 和 range(),函数 len() 返回列表的长度,即元素的个数。 range 阅读全文
posted @ 2016-05-27 23:13 七月的尾巴_葵花 阅读(160) 评论(0) 推荐(0) 编辑
摘要: ython continue 语句跳出本次循环,而break跳出整个循环。 continue 语句用来告诉Python跳过当前循环的剩余语句,然后继续进行下一轮循环。 continue语句用在while和for循环中。 Python 语言 continue 语句语法格式如下: 实例: 阅读全文
posted @ 2016-05-27 23:07 七月的尾巴_葵花 阅读(157) 评论(0) 推荐(0) 编辑
摘要: #!/usr/bin/python # -*- coding: UTF-8 -*- f1 = 1 f2 = 1 for i in range(1,21): print '%12d %12d' % (f1,f2) if (i % 2) == 0: print '' f1 = f1 + f2 f2 = f1 + f2 阅读全文
posted @ 2016-05-26 17:05 七月的尾巴_葵花 阅读(171) 评论(0) 推荐(0) 编辑
摘要: #!/usr/bin/python # -*- coding: UTF-8 -*- h = 0 leap = 1 from math import sqrt from sys import stdout for m in range(101,201): k = int(sqrt(m + 1)) for i in range(2,k + 1): if m % i ... 阅读全文
posted @ 2016-05-26 17:05 七月的尾巴_葵花 阅读(198) 评论(0) 推荐(0) 编辑
摘要: #!/usr/bin/python # -*- coding: UTF-8 -*- for n in range(100,1000): i = n / 100 j = n / 10 % 10 k = n % 10 if n == i ** 3 + j ** 3 + k ** 3: print n 阅读全文
posted @ 2016-05-26 17:04 七月的尾巴_葵花 阅读(165) 评论(0) 推荐(0) 编辑
摘要: #!/usr/bin/python # -*- coding: UTF-8 -*- from sys import stdout n = int(raw_input("input number:\n")) print "n = %d" % n for i in range(2,n + 1): while n != i: if n % i == 0: ... 阅读全文
posted @ 2016-05-26 17:04 七月的尾巴_葵花 阅读(178) 评论(0) 推荐(0) 编辑
摘要: #!/usr/bin/python # -*- coding: UTF-8 -*- import time print time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time())) # 暂停一秒 time.sleep(1) print time.strftime('%Y-%m-%d %H:%M:%S',time.localti... 阅读全文
posted @ 2016-05-26 17:01 七月的尾巴_葵花 阅读(144) 评论(0) 推荐(0) 编辑
摘要: #!/usr/bin/python # -*- coding: UTF-8 -*- import time myD = {1: 'a', 2: 'b'} for key, value in dict.items(myD): print key, value time.sleep(1) # 暂停 1 秒 阅读全文
posted @ 2016-05-26 16:57 七月的尾巴_葵花 阅读(140) 评论(0) 推荐(0) 编辑
摘要: #!/usr/bin/python # -*- coding: UTF-8 -*- for i in range(1,10): for j in range(1,10): result = i * j print '%d * %d = % -3d' % (i,j,result) print '' 阅读全文
posted @ 2016-05-26 16:56 七月的尾巴_葵花 阅读(108) 评论(0) 推荐(0) 编辑
摘要: #!/usr/bin/python # -*- coding: UTF-8 -*- a = [1, 2, 3] b = a[:] print b 阅读全文
posted @ 2016-05-26 16:55 七月的尾巴_葵花 阅读(110) 评论(0) 推荐(0) 编辑
摘要: 方法一 方法二 方法三 阅读全文
posted @ 2016-05-26 16:54 七月的尾巴_葵花 阅读(196) 评论(0) 推荐(0) 编辑
摘要: #!/usr/bin/python # -*- coding: UTF-8 -*- l = [] for i in range(3): x = int(raw_input('integer:\n')) l.append(x) l.sort() print l 阅读全文
posted @ 2016-05-26 16:52 七月的尾巴_葵花 阅读(145) 评论(0) 推荐(0) 编辑
摘要: #!/usr/bin/python # -*- coding: UTF-8 -*- year = int(raw_input('year:\n')) month = int(raw_input('month:\n')) day = int(raw_input('day:\n')) months = (0,31,59,90,120,151,181,212,243,273,304,334) if... 阅读全文
posted @ 2016-05-26 16:49 七月的尾巴_葵花 阅读(174) 评论(0) 推荐(0) 编辑
摘要: #!/usr/bin/python # -*- coding: UTF-8 -*- import math for i in range(10000): #转化为整型值 x = int(math.sqrt(i + 100)) y = int(math.sqrt(i + 268)) if(x * x == i + 100) and (y * y == i + 26... 阅读全文
posted @ 2016-05-26 16:48 七月的尾巴_葵花 阅读(126) 评论(0) 推荐(0) 编辑
摘要: #!/usr/bin/python # -*- coding: UTF-8 -*- i = int(raw_input('净利润:')) arr = [1000000,600000,400000,200000,100000,0] rat = [0.01,0.015,0.03,0.05,0.075,0.1] r = 0 for idx in range(0,6): if i>arr[id... 阅读全文
posted @ 2016-05-26 16:48 七月的尾巴_葵花 阅读(147) 评论(0) 推荐(0) 编辑
摘要: #!/usr/bin/python # -*- coding: UTF-8 -*- for i in range(1,5): for j in range(1,5): for k in range(1,5): if( i != k ) and (i != j) and (j != k): print i,j,k ... 阅读全文
posted @ 2016-05-26 16:47 七月的尾巴_葵花 阅读(168) 评论(0) 推荐(0) 编辑
摘要: 算术运算符 以下假设变量a为10,变量b为20: 算术运算符的操作: 比较运算符 以下假设变量a为10,变量b为20: 比较运算符的操作: 赋值运算符 以下假设变量a为10,变量b为20: 赋值运算符的操作: 位运算符 按位运算符是把数字看作二进制来进行计算的。Python中的按位运算法则如下: 下 阅读全文
posted @ 2016-05-26 16:28 七月的尾巴_葵花 阅读(151) 评论(0) 推荐(0) 编辑
摘要: 变量赋值 Python中的变量不需要声明,变量的赋值操作既是变量声明和定义的过程。 每个变量在内存中创建,都包括变量的标识,名称和数据这些信息。 每个变量在使用前都必须赋值,变量赋值以后该变量才会被创建。 等号(=)用来给变量赋值。 等号(=)运算符左边是一个变量名,等号(=)运算符右边是存储在变量 阅读全文
posted @ 2016-05-26 16:20 七月的尾巴_葵花 阅读(257) 评论(0) 推荐(0) 编辑
摘要: my_name = 'Zed A. Shaw' my_age = 35 # not a lie my_height = 74 # inches my_weight = 180 # lbs my_eyes = 'Blue' my_teeth = 'White' my_hair = 'Brown' print "Let's talk about %s." % my_name print "He's ... 阅读全文
posted @ 2016-05-25 18:07 七月的尾巴_葵花 阅读(118) 评论(0) 推荐(0) 编辑
摘要: 打印得出: There are 100 cars available.There are only 30 drivers available.There will be 70 empty cars today.We can transport 120.0 people today.We have 9 阅读全文
posted @ 2016-05-24 12:26 七月的尾巴_葵花 阅读(263) 评论(0) 推荐(0) 编辑
摘要: + plus 加号- minus 减号/ slash 斜杠* asterisk 星号% percent 百分号< less-than 小于号> greater-than 大于号<= less-than-equal 小于等于号>= greater-than-equal 大于等于号 打印得出: I wi 阅读全文
posted @ 2016-05-24 11:48 七月的尾巴_葵花 阅读(322) 评论(0) 推荐(0) 编辑
摘要: 打印的到: Hello World!Hello AgainI like typing this.This is fun.Yay! Printing.I'd much rather you 'not'.I "said" do not touch this. 阅读全文
posted @ 2016-05-24 10:31 七月的尾巴_葵花 阅读(149) 评论(0) 推荐(0) 编辑
摘要: #!/usr/bin/python # -*- coding: utf-8 -*- def ntom(x,size,mod): t=[0]*(size) j=0 while x and j1 a和d不能一起去 a+d!=2 a,e,f三人里要去两人 a+e+f==2 b和c都去 或者 都不去 (b+c==0 or b+c==2) c和d两人中只去一个 c+d=... 阅读全文
posted @ 2016-05-23 23:51 七月的尾巴_葵花 阅读(463) 评论(0) 推荐(0) 编辑
摘要: #!/usr/bin/python # -*- coding: utf-8 -*- def gcd(x,y): #最大公因子 if x>y:x%=y while x: x,y=y%x,x return y def lcm(x,y): #最小公倍数 return x*y/gcd(x,y) def jhua(x): t=gcd(... 阅读全文
posted @ 2016-05-23 23:50 七月的尾巴_葵花 阅读(294) 评论(0) 推荐(0) 编辑
摘要: #!/usr/bin/python # -*- coding: utf-8 -*- from collections import deque from math import log10 def permute(seq, index): seqc = seq[:] seqn = [seqc.pop()] divider = 2 while seqc: inde... 阅读全文
posted @ 2016-05-23 23:49 七月的尾巴_葵花 阅读(385) 评论(0) 推荐(0) 编辑
摘要: #!/usr/bin/python # -*- coding: utf-8 -*- from collections import deque def z69(): '''猜牌术(1) 魔术师,最上面一张是黑a,第2次从上到下数2张放在最 底下,然后翻开是黑k,然后再从上到下数3张放 在最底下,是黑q,第k次数k张,依次翻开,得 到黑a~1;问原始的牌序''' ss=13 ... 阅读全文
posted @ 2016-05-23 23:47 七月的尾巴_葵花 阅读(238) 评论(0) 推荐(0) 编辑
摘要: #!/usr/bin/python # -*- coding: utf-8 -*- from math import sqrt import random def daoxu(n): d=n s=0 while d!=0: d,f=divmod(d,10) s=f+s*10 return s def z85(): #任意取一个十进制数如12... 阅读全文
posted @ 2016-05-23 23:45 七月的尾巴_葵花 阅读(292) 评论(0) 推荐(0) 编辑
摘要: #!/usr/bin/python # -*- coding: utf-8 -*- def z94(): #斐波那契数列 def filie(x): a,b,t=1,1,0 if x==1 or x==2:return 1 while t!=x-2: a,b,t=b,a+b,t+1 retur... 阅读全文
posted @ 2016-05-23 23:44 七月的尾巴_葵花 阅读(251) 评论(0) 推荐(0) 编辑
摘要: #!/usr/bin/python # -*- coding: utf-8 -*- from random import shuffle class caigame: win=False flag=False life=12 what=-1 s1='' map1=[] thenum=0 def start(self): ... 阅读全文
posted @ 2016-05-23 23:38 七月的尾巴_葵花 阅读(268) 评论(0) 推荐(0) 编辑
摘要: from math import sqrt from datetime import date def k1(): #某人是1999年9月29日生日 #问到2006年9月29日他活了多少天 a=date(1999,9,29) b=date(2006,9,29) c=str(b-a).split(" ") print int(c[0]) ... 阅读全文
posted @ 2016-05-23 23:32 七月的尾巴_葵花 阅读(422) 评论(0) 推荐(0) 编辑
摘要: #!/usr/bin/env python # -*- coding: utf-8 -*- """ @desc: search in mail box """ import unittest import os import sys from selenium import webdriver from selenium.webdriver.common.keys import K... 阅读全文
posted @ 2016-05-20 18:05 七月的尾巴_葵花 阅读(301) 评论(0) 推荐(0) 编辑
摘要: #!/usr/bin/env python # -*- coding: utf-8 -*- """ 我们多添加一些测试场景,比如:删除邮件,查找邮件,发送邮件等等 """ import unittest import os import sys from selenium import webdriver cur_dir = os.getcwd() sys.path.append(cur_di... 阅读全文
posted @ 2016-05-20 16:18 七月的尾巴_葵花 阅读(228) 评论(0) 推荐(0) 编辑
摘要: #!/usr/bin/env python # -*- coding: utf-8 -*- """ @desc: delete mail 我们多添加一些测试场景,比如:删除邮件,查找邮件,发送邮件等等 """ import unittest import os import sys from selenium import webdriver cur_dir = os.getcw... 阅读全文
posted @ 2016-05-20 01:35 七月的尾巴_葵花 阅读(260) 评论(0) 推荐(0) 编辑
摘要: #!/usr/bin/env python # -*- coding: utf-8 -*- """ @desc: 定制浏览器 """ import unittest import os import time from selenium import webdriver class TestConfigFirefox(unittest.TestCase): def se... 阅读全文
posted @ 2016-05-20 01:34 七月的尾巴_葵花 阅读(256) 评论(0) 推荐(0) 编辑
摘要: #!/usr/bin/env python # -*- coding: utf-8 -*- """ @desc: 测试126邮箱的登陆功能 1.使用公共方法public.login 2.将测试数据放在xml文件中,使用数据驱动(/test_data/login.xml) 3.这里使用xml.dom.minidom读取xml数据 """ import unittest import x... 阅读全文
posted @ 2016-05-20 00:13 七月的尾巴_葵花 阅读(385) 评论(0) 推荐(0) 编辑
摘要: #!/usr/bin/env python # -*- coding: utf-8 -*- """ @desc: 将登陆动作封装成function """ import unittest import sys import os from selenium import webdriver from selenium.webdriver.common.keys import Keys... 阅读全文
posted @ 2016-05-20 00:09 七月的尾巴_葵花 阅读(267) 评论(0) 推荐(0) 编辑