摘要:
#!/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 阅读全文
摘要:
#!/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 ... 阅读全文
摘要:
#!/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 阅读全文
摘要:
#!/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: ... 阅读全文
摘要:
#!/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... 阅读全文
摘要:
#!/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 秒 阅读全文
摘要:
#!/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 '' 阅读全文
摘要:
#!/usr/bin/python # -*- coding: UTF-8 -*- a = [1, 2, 3] b = a[:] print b 阅读全文
摘要:
方法一 方法二 方法三 阅读全文
摘要:
#!/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 阅读全文
摘要:
#!/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... 阅读全文
摘要:
#!/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... 阅读全文
摘要:
#!/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... 阅读全文
摘要:
#!/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 ... 阅读全文
摘要:
算术运算符 以下假设变量a为10,变量b为20: 算术运算符的操作: 比较运算符 以下假设变量a为10,变量b为20: 比较运算符的操作: 赋值运算符 以下假设变量a为10,变量b为20: 赋值运算符的操作: 位运算符 按位运算符是把数字看作二进制来进行计算的。Python中的按位运算法则如下: 下 阅读全文
摘要:
变量赋值 Python中的变量不需要声明,变量的赋值操作既是变量声明和定义的过程。 每个变量在内存中创建,都包括变量的标识,名称和数据这些信息。 每个变量在使用前都必须赋值,变量赋值以后该变量才会被创建。 等号(=)用来给变量赋值。 等号(=)运算符左边是一个变量名,等号(=)运算符右边是存储在变量 阅读全文